C#处理PropertyChanged事件
示例
片段
public class BugReport : INotifyPropertyChanged{
public string Title { ... }
public BugStatus Status { ... }
}
...
private void BugReport_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
var bugReport = (BugReport)sender;
switch (e.PropertyName)
{
case nameof(bugReport.Title):
Console.WriteLine("{0} changed to {1}", e.PropertyName, bugReport.Title);
break;
case nameof(bugReport.Status):
Console.WriteLine("{0} changed to {1}", e.PropertyName, bugReport.Status);
break;
}
}
...
var report = new BugReport();
report.PropertyChanged += BugReport_PropertyChanged;
report.Title = "Everything is on fire and broken";
report.Status = BugStatus.ShowStopper;
控制台输出
标题更改为“一切着火了”
状态已更改为ShowStopper
以上是 C#处理PropertyChanged事件 的全部内容, 来源链接: utcz.com/z/321338.html