Data Binding Notifications绑定通知
2012-09-04 15:06
225 查看
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; }
}
}
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; }
}
}
相关文章推荐
- WPF学习09:数据绑定之 Binding to List Data
- Android DataBinding (六) EditText 绑定 TextChangedListener 和 FocusChangeListener
- 运用模型绑定和web窗体显示和检索数据(Retrieving and displaying data with model binding and web forms)
- Google Data Binding Library 谷歌官方数据绑定库(五) 可观察的数据对象
- Databinding在自定义ViewGroup中如何绑定view
- Android DataBinding(数据绑定)详解(一)
- Android DataBinding数据绑定技术在传统ListView中的使用简例
- SilverLight DataBinding绑定详解(学习笔记)——转载
- Android官方数据绑定框架DataBinding
- 数据绑定数据库详解Android Data Binding Library
- Android Data Binding数据绑定详解
- Data Binding MVVM 数据绑定 总结
- Android官方数据绑定框架DataBinding
- 译文:Silverlight 3.0 新功能之七 : XAML元素的数据绑定(XAML Element Databinding)
- jface databinding:使用CheckboxTableViewer实现表中(Set)对象与CheckTable中选中条目数据绑定
- android数据绑定框架DataBinding使用
- DataBinding?资料绑定?
- Control.DataBinding数据绑定细解
- Android官方数据绑定框架DataBinding(二)
- Android官方数据绑定框架DataBinding(一)