我正在一个遵循 MVVM 的 WPF 应用程序中工作。
我在 Combobox 的 text 属性中使用了绑定(bind),并且此组合位于选项卡内。
每当我切换选项卡时,Combobox 的 text 属性 cahnged 都会被触发,并且 text 设置为 string.Empty。
最佳答案
如果您不希望文本为空,您可以尝试:
看法<ComboBox Text={Binding ComboxText} ... />
从评论编辑:<ComboBox Text={Binding ComboxText, TargetNullValue=SomeValue} ... />
View 模型
/*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*/
}
}
}
关于选项卡更改时的 WPF 组合框文本绑定(bind)问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4792468/