简体   繁体   English

不实现接口成员'System.ComponentModel.INotifyPropertyChanged.PropertyChanged'

[英]Does not implement interface member 'System.ComponentModel.INotifyPropertyChanged.PropertyChanged'

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)
        {

        }

    }
}

I am getting the following error: Error 'MimicCreation.TreeManager' does not implement interface member 'System.ComponentModel.INotifyPropertyChanged.PropertyChanged' upon compile. 我收到以下错误:编译时错误'MimicCreation.TreeManager'未实现接口成员'System.ComponentModel.INotifyPropertyChanged.PropertyChanged'。 I have an observable collection, which I want to be able to get access to notifications when each item in the observable collection is changed, I cant see what I have done wrong. 我有一个可观察的集合,当可观察的集合中的每个项目都更改时,我希望能够访问通知,但看不到我做错了什么。 Any ideas please? 有什么想法吗?

Thanks. 谢谢。

You're all at 6's and 7's 你们都在6和7

Firstly this class doesn't need to implement INotifyPropertyChanged for you to subscribe to the event on the observable collection. 首先,此类无需实现INotifyPropertyChanged即可让您订阅可观察集合上的事件。

Also if you are trying (and this is how I read your question) to see if the items in the collection have changed then they need to implement INotifyPropertyChanged in some why either directly or by inherting fron ObservableObject. 另外,如果您正在尝试(这就是我阅读您的问题的方式)以查看集合中的项目是否已更改,则他们需要直接或通过继承ObservableObject来实现INotifyPropertyChanged。

Secondly it's PropertyChanged you need to subscribe to not collection changed. 其次,它是PropertyChanged,您需要订阅未更改的集合。

The error message has nothing to do with the observable collection. 该错误消息与可观察的集合无关。 You declare that TreeManager implements INotifyPropertyChanged , so you have to implement the interface members. 您声明TreeManager实现INotifyPropertyChanged ,因此您必须实现接口成员。

According to the documentation on INotifyPropertyChanged , in order to do this you must implement the event PropertyChanged -- exactly what the compiler complains about. 根据documentation on INotifyPropertyChangeddocumentation on INotifyPropertyChanged ,为此,您必须实现PropertyChanged事件-正是编译器抱怨的事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WPF PropertyChanged代码错误:无法实现&#39;System.ComponentModel.INotifyPropertyChanged - WPF PropertyChanged code error: cannot implement 'System.ComponentModel.INotifyPropertyChanged INotifyPropertyChanged的PropertyChanged成员始终为null - PropertyChanged member of INotifyPropertyChanged always null INotifyPropertyChanged的PropertyChanged成员始终为null - PropertyChanged member for INotifyPropertyChanged is always null 无法序列化System.ComponentModel.ISite类型的成员System.ComponentModel.MarshalByValueComponent.Site,因为它是接口 - Cannot serialize member System.ComponentModel.MarshalByValueComponent.Site of type System.ComponentModel.ISite because it is an interface 没有实现接口成员 - does not implement interface member 什么时候实现iNotifyPropertyChanged接口? - When to implement iNotifyPropertyChanged interface? 没有实现接口成员&#39;System.Icomparable.CompareTo(object)&#39;? - Does not implement interface member 'System.Icomparable.CompareTo(object)'? &#39;未实现接口成员&#39;System.ICloneable.Clone()&#39; - 'does not implement interface member 'System.ICloneable.Clone()' 为什么ObservableCollection会隐藏INotifyPropertyChanged.PropertyChanged - Why does ObservableCollection hide INotifyPropertyChanged.PropertyChanged JSONWebService没有实现接口成员 - JSONWebService does not implement interface member
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM