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

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

This is an example code:

public class MyParent : INotifyPropertyChanged
{
    List MyChildren;

    public bool IsChanged
    {
        get
               


        
5条回答
  •  南旧
    南旧 (楼主)
    2021-02-09 01:18

    You can simplify things for yourself by storing your children in an ItemObservableCollection, as discussed in this answer. That would allow you to do this:

    private ItemObservableCollection children;
    
    public MyParent()
    {
        this.children = new ItemObservableCollection();
        this.children.ItemPropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
        {
            if (string.Equals("IsChanged", e.PropertyName, StringComparison.Ordinal))
            {
                this.RaisePropertyChanged("IsChanged");
            }
        };
    }
    

提交回复
热议问题