最終更新:2020-04-03 (金) 14:29:24 (1445d)
INotifyPropertyChanged
Top / INotifyPropertyChanged
プロパティ値が変更されたことをクライアント (通常はバインド元クライアント) に通知するために使用する
概要
- ソースの値が変更されたことをBindingオブジェクトに通知するためには、クラスにINotifyPropertyChanged?インターフェイスを実装し、値の変更時にPropertyChanged?イベントを発生させる
定義
public interface INotifyPropertyChanged { // 概要: // プロパティ値が変更されたときに発生します。 event PropertyChangedEventHandler PropertyChanged; }
実装
//インターフェイスを実装 public class バインディングに使うクラス: INotifyPropertyChanged { double _hoge; public double Hoge { get { return _hoge; } private set { _hoge = value; OnPropertyChanged("Hoge");//値の変更を通知 } } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = this.PropertyChanged; if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); } ... }
関連
- データバインディング
- INotifyCollectionChanged?
- PropertyChangedEventArgs?
- event
- RaisePropertyChanged?