파생 클래스에서 기본 클래스 이벤트를 구독하는 데 어려움을 겪고 있습니다. 그 목적은 propertyChild를 얻을 때마다 내 기본 클래스에서 이벤트를 발생시켜 결과적으로 파생 클래스에서 메서드를 실행하는 것입니다.파생 클래스의 기본 클래스 이벤트 구독
namespace MyNamespace
{
public delegate void EventHandler();
[Serializable]
public class ChartGroupCollection : ObservableCollection<ChartGroup>, INotifyCollectionChanged
{
public ChartGroupCollection()
{
base.DirtyFlagging += new EventHandler(MethodIWantToRun); //subscription to event
}
void MethodIWantToRun()
{
SomeVariable++;
}
#region NotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
[Serializable]
public class ChartGroup : INotifyPropertyChanged
{
public event EventHandler<EventArgs> DirtyFlagging;
protected virtual void OnDirtyFlagging(EventArgs e)
{
EventHandler<EventArgs> handler = DirtyFlagging;
if (handler != null)
{
handler(this, e);
}
}
public ChartGroup()
{
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
DirtyFlagging.Invoke(this, someeventargs); //Where i want to invoke the event
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
주제 끄기 : 여기 내 코드의 축소 버전입니다 그렇지 'ObservableCollection'이 이미 그것을 구현했기 때문에'ChartGroupCollection' 클래스에'INotifyCollectionChanged' 인터페이스를 구현할 필요가 있습니다; 편집 : 오타 – grabthefish
기본 클래스와 파생 클래스라는 용어를 사용하는 것은 다소 복잡합니다. ChartGroupCollection의 기본 클래스는 ObservableCollection이고 차트 그룹은 – AxdorphCoder