http://blogs.wankuma.com/rti/archive/2008/06/10/142627.aspx
データバインドの着火方法(その2)
の続き・・・と言うか更にメモ。
NortifyPropertyChanged
で LINQ to Objects 使って存在チェックする必要はなかったです。
以下、なぐり書きコード。
public class MyTextBox : TextBox
private string _Value;
[Bindable(BindableSupport.Default)]
public string Value {
get { return this._Value; }
set {
if (this._Value == value) reurn;
this._Value = value;
NortifyPropertyChanged("Value")
}
}
private void NortifyPropertyChanged(string propertyName) {
var b = this.DataBindings[propertyName];
if (b == null) return;
if (!b.IsBinding) return;
if (b.DataSourceUpdateMode == DataSourceUpdateMode.Never) return;
b.WriteValue();
}
}
コレクション中にターゲットアイテムが存在するかどうかを事前に確認するためのメソッドが見つからなかったので前回のコードを書いたのですが、存在しない場合は、例外エラーではなくて null が返るだけなので、上記のようにした方が高速だしスッキリ書けるみたい。