开发者

Listen to the PropertyChanged event of any item in an ObservableCollection<INotifyPropertyChanged> [duplicate]

开发者 https://www.devze.com 2023-01-12 00:10 出处:网络
This question already has answers here: ObservableCollection that also monitors changes on the elements in collection
This question already has answers here: ObservableCollection that also monitors changes on the elements in collection (8 answers) Closed 4 years ago.

I've created a wrapper collection for ObservableCollection that subscribes to each items PropertyChanged event and rethrows it as its own event ItemPropertyChanged. I did this using a similar method to what I described here. Is there a better way? Am 开发者_Go百科I missing another .NET collection that already has this type of behavior?


I'm assuming that you are firing this event in order to compute an aggregate. I have a different solution to this problem. Consider using Update Controls with linq. You can declaratively describe your aggregate with linq, and Update Controls will track its dependencies within your collection. Whenever the collection changes, or any of the referenced properties changes, then it will reevaluate the aggregate.


Just use System.ComponentModel.BindingList<T> instead. The ListChanged event it has will fire when any item in the list fires it's INotifyPropertyChanged.

0

精彩评论

暂无评论...
验证码 换一张
取 消