INotifyPropertyChanged
当其中的特定对象的变量发生任何变化时,我会通知类。
下面是课程:
public class MyClass
{
public SecClass MyObj { get; set; }
//A few more variables
}
SecClass:
public class SecClass:INotifyPropertyChanged
{
private bool _noti= false;
public bool Noti
{
get { return _noti; }
set
{
_noti= value;
NotifyPropertyChanged("Noti");
}
}
//A few more variables
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
}
这是我进行事件注册的函数:
public void Register()
{
MyObj.PropertyChanged += MyObj_PropertyChanged;
}
功能起作用并且注册完成,但是当涉及到更改时,它显示Property Change
为空(我猜某处注册已删除,在发生更改之前,我该如何检查?)