【发布时间】:2020-08-26 07:11:56
【问题描述】:
如何在 B 类中收听来自 A 类的 PropertyChanged 事件?我想听听 A 类属性的变化。
class A : INotifyPropertyChanged
{
private int _x;
public int X
{
get => _x;
set
{
if (_x == value) return;
_x = value;
OnPropertyChanged(nameof(X));
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
class B
{
public B(int x)
{
// In this class I want to listen to changes of the property X from class A
}
}
【问题讨论】:
标签: c# .net event-handling