c# - 未实现接口(interface)成员 'System.ComponentModel.INotifyPropertyChanged.PropertyChanged'

标签 c# silverlight

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/

相关文章:

c# - 如何从我的 ASP.NET Core 应用程序中永久注销用户?

silverlight - 在 Silverlight 4 中拖放文件上传?

silverlight - 是否可以在没有IIS的情况下使用Silverlight RiaServices?

.net - View 和 View 模型关系

c# - 在 Visual Studio 中使空格像选项卡一样工作的技巧

c# - 优雅地关闭多线程应用程序?

c# - 以编程方式调用 C# 编译器来编译 C# 代码

c# - Windows Phone 列表框选择到文本框

c# - Silverlight 4 线程问题

visual-studio - 如何在没有 Visual Studio 的情况下构建 Silverlight 4 应用程序?