![](/img/trans.png)
[英]TextBox bound to brush not updating UI despite calling OnPropertyChanged
[英]Bound Textbox/Labels not updating when OnPropertyChanged fired
我有一个简单的应用程序,该应用程序使用BindingList <(Person)>来存储有关员工的信息(Windows窗体)。 Person具有多个属性,例如Name,DateOfBirth等,并实现了INotifyPropertyChanged。
BindingList <(Person)>(人员)已绑定到绑定源。 DataGridView控件绑定到此源,并且随着预期的属性更改在DataGridView上更新。 例如,当我更改一个人的年龄时,DataGridView会立即更新。
当我使用相同的绑定源其他控件时,会发生我的问题。 我使用与DataGridView相同的绑定源,将文本框的text属性绑定到Person.Name。 对Person.Name属性的更改将在DataGridView上更新,但不会对文本框进行更改。
属性更改时,如何使文本框(如DataGridView)更新?
克里斯
很快,这未经测试,可能需要由Dispatcher处理。 尝试使用以下内容代替您的TextBox
public class DispatchedTextBox : TextBox
{
DispatchEvent _propertyChanged = new DispatchEvent();
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
this._propertyChanged.Fire(this, e);
}
protected override event PropertyChangedEventHandler PropertyChanged
{
add { this._propertyChanged.Add(value); }
remove { this._propertyChanged.Remove(value); }
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.