Does not implement interface member 'System.ComponentModel.INotifyPropertyChanged.PropertyChanged'

15,190

Solution 1

You're all at 6's and 7's

Firstly this class doesn't need to implement INotifyPropertyChanged for you to subscribe to the event on the observable collection.

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.

Secondly it's PropertyChanged you need to subscribe to not collection changed.

Solution 2

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.

According to the documentation on INotifyPropertyChanged, in order to do this you must implement the event PropertyChanged -- exactly what the compiler complains about.

Share:
15,190
Simon Griffiths
Author by

Simon Griffiths

Updated on June 05, 2022

Comments

  • Simon Griffiths
    Simon Griffiths almost 2 years
    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. 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.