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));
}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章