原文:
WPF 属性变更通知类的实现
平时用依赖属性多一些,普通属性的变更通知知道有这个方法,但是老是忘记名字,再写一遍吧。
public class Student : INotifyPropertyChanged
{
private string studentID;
public string StudentID
{
get { return studentID; }
set
{
studentID = value;
NotifyPropertyChange("StudentID");
}
}
private string studentName;
public string StudentName
{
get { return studentName; }
set
{
studentName = value;
NotifyPropertyChange("StudentName");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChange(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}