我使用 Winforms 数据绑定,并且我有派生类,基类在其中实现IPropertychanged
:
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propertyName) {
var handler = this.PropertyChanged;
if (handler != null) {
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
每个属性设置器调用:
protected void SetField<T>(ref T field, T value, string propertyName) {
if (!EqualityComparer<T>.Default.Equals(field, value)) {
field = value;
IsDirty = true;
this.RaisePropertyChanged(propertyName);
}
}
一个典型的 Propertysetter:
public String LocalizationItemId {
get {
return _localizationItemId;
}
set {
SetField(ref _localizationItemId, value, "LocalizationItemId");
}
}
属性绑定到文本框的方式
private DerivedEntity derivedEntity
TextBoxDerivedEntity.DataBindings.Add("Text", derivedEntity, "Probenname");
如果我以编程方式将文本分配给文本框,则文本框不会显示它。但我可以手动编辑文本框。