WPF

CallerMemberName 特性

2019-10-11  本文已影响0人  落地成佛

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

上一篇下一篇

猜你喜欢

热点阅读