【发布时间】:2010-12-09 14:47:03
【问题描述】:
我有一个存储 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");
}
所以我在表单之外设置了this.Food,然后它会显示在 UI 中。
如果我修改this.Food,它会正确更新。如果我以编程方式修改 UI,例如:
this.textBox.Text = "NewFruit",它不会更新 this.Food。
为什么会这样?我还为 Fruit.Name 实现了INotifyPropertyChanged,但还是一样。
【问题讨论】:
标签: c# .net winforms data-binding