选项卡更改上的WPF Combobox文本绑定问题

时间:2011-01-25 10:40:11

标签: wpf mvvm wpf-controls binding

我正在使用跟随MVVM的WPF应用程序。

我在Combobox的text属性中使用了绑定,这个组合在一个标签内。

当我切换标签时,Combobox的文本属性cahnged被触发,文本被设置为string.Empty。

1 个答案:

答案 0 :(得分:0)

如果您不希望文本为空,您可以尝试:

查看
<ComboBox Text={Binding ComboxText} ... />

从评论中编辑:
<ComboBox Text={Binding ComboxText, TargetNullValue=SomeValue} ... />

ViewModel

/*INotifyPropertyChanged property*/
private string comboxText;
public string ComboxText 
{  get { return comboxText; }  
   set { 
      if (value != comboxText)  
      {// value changed ->  
         if (!string.IsNullOrWhiteSpace(value))   
         {// value not null, empty, whitespace ->  
            comboxText = value;
         }  
         /*INPC code*/
      }  
   }
}
相关问题