我有一个基本属性存储Fruit类型的对象:
Fruit food;
public Fruit Food
{
get {return this.food;}
set
{
this.food= value;
this.RefreshDataBindings();
}
}
public void RefreshDataBindings()
{
this.textBox.DataBindings.Clear();
this.textBox.DataBindings.Add("Text", this.Food, "Name");
}
Run Code Online (Sandbox Code Playgroud)
所以我this.Food
在表单外面设置然后它显示在UI中.
如果我修改this.Food
,它会正确更新.如果我以编程方式修改UI,如:
this.textBox.Text = "NewFruit"
,它没有更新this.Food.
为什么会这样?我也INotifyPropertyChanged
为Fruit.Name 实现了,但仍然是一样的.