我使用.net 3.5的WinForms,數據綁定雙向數據綁定在的WinForms,INotifyPropertyChanged的基類中實現
我已經派生類的基類實現IPropertychanged
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propertyName) {
var handler = this.PropertyChanged;
if (handler != null) {
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
每個propertysetter電話:
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");
如果我以編程方式將文本分配到文本框的方式,文本框不顯示它。但我可以手動編輯文本框。
的WinForms數據綁定,我從來沒有聽說過,但肯定即時通訊初學者:) – Krekkon