INotifyPropertyChanged: Notify another class

前端 未结 2 1480
醉话见心
醉话见心 2021-02-09 14:57

I have a class (let\'s call it MyContainerClass)that is a container for several other classes (let\'s call them ClassA to ClassF). C

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-09 15:23

    Okay, here is what I did after staring at Eren's solution for a while: I also implemented the INotifyPropertyChanged for the container class and registered the PropertyChanged event for each object.

    objA.PropertyChanged += updateCount;
    objB.PropertyChanged += updateCount;
    objC.PropertyChanged += updateCount;
    

    ...and so on. Then I added the following method

    private void updateCount(object sender, PropertyChangedEventArgs e)
    {
        OnPropertyChanged("Count");
    }
    

    Now I have the behavior that I want.

提交回复
热议问题