【发布时间】:2010-11-15 00:14:28
【问题描述】:
我的视图模型中有一个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"/>
【问题讨论】:
-
我很想知道这种行为在 Silverlight 中是否相同?任何人!
-
Silverlight 中的行为相同,但 Silverlight 中不支持 NotifyOnSourceUpdated 和 UpdateSourceTrigger 等数据绑定属性。
标签: c# wpf silverlight xaml data-binding