1、 callerMemberName概述
image.png
2、wpf中应用
public class NotifyViewModel : BaseViewModel
{
private string name = "";
public string Name
{
get { return Name; }
set
{
Name = value;
//封装后就只需要这要简单的调用就可以了
OnPropertyChanged();
}
}
}
public class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName]string propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
网友评论