使用以下代码在文本框上绑定(bind)一个属性。在 UI 中修改文本框值时属性值正在刷新。但是我将值分配给代码 behind[txtNoOfSessions.Text = "1"] 上的文本框,但它没有反射(reflect)属性中的值。
<TextBox x:Name="txtNoOfSessions"
Text="{Binding Path=NoOfSessions,Mode=TwoWay}"
Height="23" Width="120" />
最佳答案
在属性上使用 INotifyPropertyChanged。否则,它不会在 UI 加载后更新。
http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx
例子:
public string PhoneNumber
{
get
{
return this.phoneNumberValue;
}
set
{
if (value != this.phoneNumberValue)
{
this.phoneNumberValue = value;
NotifyPropertyChanged("PhoneNumber");
}
}
}
https://stackoverflow.com/questions/9090127/