How to let a parent class know about a change in its children?

后端 未结 5 1270
走了就别回头了
走了就别回头了 2021-02-09 00:28

This is an example code:

public class MyParent : INotifyPropertyChanged
{
    List MyChildren;

    public bool IsChanged
    {
        get
               


        
5条回答
  •  清歌不尽
    2021-02-09 00:56

    Something I do not see in your code sample provide is an actually reference of parent to child. It is not enough to simply have interface to communicate through, but you must also create the reference. Something like myChild.parent = this; followed by the binding of the event handlers across the channel, in the "parent" property of the child object it would look like:

    public INotifyPropertyChanged parent
    {
       get{return _parent;}
       set
       {
          _parent = value;
          this.PropertyChanged += _parent.RaiseChanged();
       }
    }
    

    I don't have enough context to perfect this code for you but this should move you in the right direction.

提交回复
热议问题