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的属性被修改