其他分享
首页 > 其他分享> > wpf binging Class 双向绑定 需要实现的接口

wpf binging Class 双向绑定 需要实现的接口

作者:互联网

 public class HuMan : INotifyPropertyChanged
    {
        private string name;
        private string age;
        private string sex;

        public event PropertyChangedEventHandler PropertyChanged;

        public string Name
        {
            get { return name; }
            set
            {
                name = value;
                Console.WriteLine(value);
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
            }
        }
        public string Age
        {
            get { return age; }
            set
            {
                age = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Age"));
            }
        }

        public string Sex
        {
            get { return sex; }
            set
            {
                sex = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Sex"));
            }
        }
    }

  

Class 需要实现 INotifyPropertyChanged 接口 以及在属性的 set方法里通知 外部ui 什么Name的属性被修改

标签:PropertyChanged,set,string,PropertyChangedEventArgs,value,Class,binging,wpf,publ
来源: https://www.cnblogs.com/xiongyang123/p/10682897.html