我拥有以下财产int
输入我的视图模型,该模型绑定到TextBox
。一切正常,TwoWay
绑定工作正常,除了一种情况 -
如果我清除的值TextBox
,属性设置器不会被调用,尽管值已被清除TextBox
,属性仍保持先前的值。
有人遇到过类似的问题吗?有什么解决方法吗?
这是财产——
public int MaxOccurrences
{
get
{
return this.maxOccurrences;
}
set
{
if (this.maxOccurrences != value)
{
this.maxOccurrences = value;
base.RaisePropertyChanged("MaxOccurrences");
}
}
}
这是我在 xaml 中绑定属性的方式 -
<TextBox Text="{Binding Path=MaxOccurrences, Mode=TwoWay,
NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Center" Width="30" Margin="0,0,5,0"/>
我有类似的问题。
您只需将代码更新为:
<TextBox Text="{Binding Path=MaxOccurrences, Mode=TwoWay, TargetNullValue={x:Static sys:String.Empty},
NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Center" Width="30" Margin="0,0,5,0"/>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)