namespace MimicCreation
{
public class TreeManager : INotifyPropertyChanged
{
public TreeManager() { }
public TreeManager(string title, string type, string filename)
{
this.childElementsValue.CollectionChanged += this.OnCollectionChanged;
Title = title;
Type = type;
FileName = filename;
}
public string Title { get; set; }
public string Type { get; set; }
public string FileName { get; set; }
public override string ToString()
{
return Title;
}
private ObservableCollection<TreeManager> childElementsValue = new ObservableCollection<TreeManager>();
public ObservableCollection<TreeManager> ChildElements
{
get { return childElementsValue; }
set { childElementsValue = value; }
}
public void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
foreach (TreeManager item in e.NewItems)
{
((System.ComponentModel.INotifyPropertyChanged)item).PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(OnPropertyChanged);
}
break;
}
}
public void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
}
}
}
我收到以下错误:错误“MimicCreation.TreeManager”在编译时未实现接口(interface)成员“System.ComponentModel.INotifyPropertyChanged.PropertyChanged”。我有一个可观察集合,当可观察集合中的每个项目发生更改时,我希望能够访问通知,我看不到我做错了什么。请问有什么想法吗?
谢谢。
最佳答案
你们都在 6 分和 7 分
首先,此类不需要实现 INotifyPropertyChanged 来订阅可观察集合上的事件。
此外,如果您尝试(这就是我阅读您的问题的方式)查看集合中的项目是否已更改,那么它们需要直接或通过从 ObservableObject 继承来实现 INotifyPropertyChanged。
其次是 PropertyChanged,您需要订阅未更改的集合。
关于c# - 未实现接口(interface)成员 'System.ComponentModel.INotifyPropertyChanged.PropertyChanged',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7360618/