Data Binding Notifications绑定通知

The standard way for a View Model to serve as a binding source is by implementing the INotifyPropertyChanged interface defined in the System.ComponentModel namespace. This interface has an exceptionally simple definition:
public interface INotifyPropertyChanged { event PropertyChangedEventHandler PropertyChanged; }
The PropertyChangedEventHandler delegate is associated with the PropertyChangedEventArgs class, which defines one property: PropertyName of type string. When a class implements INotifyPropertyChanged, it fires a PropertyChanged event whenever one of its properties changes.

public class SimpleViewModel : INotifyPropertyChanged

{ double totalScore;

public event PropertyChangedEventHandler PropertyChanged;

public double TotalScore

{

set { if (totalScore != value)

{

totalScore = value;

if (PropertyChanged != null)

PropertyChanged(this, new PropertyChangedEventArgs("TotalScore"));

}

}

get { return totalScore; }

}

}

posted on 2012-09-04 15:06  GIS-MAN  阅读(225)  评论(0编辑  收藏  举报

导航