C#引发PropertyChanged事件
示例
片段
public class Person : INotifyPropertyChanged { private string _address; public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public string Address { get { return _address; } set { if (_address == value) { return; } _address = value; OnPropertyChanged(nameof(Address)); } } } ... var person = new Person(); person.PropertyChanged += (s,e) => Console.WriteLine(e.PropertyName); person.Address = "123 Fake Street";
控制台输出
地址