我正在尝试将方法添加到父类中包含的PropertyChangedEventHandler。它可以看到继承的事件,并且不会抛出异常,但是在运行事件提升器时,它不会显示为已添加事件。
父类(可以看到这两个类,但PropertyChanged不会保留添加内容)
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Raises the PropertyChanged event.
/// </summary>
/// <param name="propertyName">Name of the Property that was changed</param>
/// <param name="passThroughSender">Optional reference to another sender if this instance is not intended to be the sender</param>
protected virtual void NotifyPropertyChanged(string propertyName, object passThroughSender = null)
{
if (PropertyChanged != null)
PropertyChanged(passThroughSender ?? this, new PropertyChangedEventArgs(propertyName));
}
继承类(它继承并查看两个属性)
public class VMViewPage : ViewModelBase, INotifyPropertyChanged, IHandleCleanup
{
...
}
订阅类contstructor(它会更改属性,但不会添加或抛出异常。)
VMViewPage parentContext = BoundWindow.DataContext as VMViewPage;
parentContext.PropertyChanged += VersionPropertyChanged;
订阅类事件提升者(它会点击并调用提升者,但不会做任何事情,因为它从未正确添加)
public string VersionID
{
get { return (_versionID); }
private set { _versionID = value; NotifyPropertyChanged("VersionID", this); }
}