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

Posted on 2019-04-10 13:29  熊先生丶  阅读(145)  评论(0编辑  收藏  举报
 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的属性被修改