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 I missing another .NET collection that already has this type of behavior?
Listen to the PropertyChanged event of any item in an ObservableCollection<INotifyPropertyChanged> [duplicate]
Asked Answered
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
.
© 2022 - 2024 — McMap. All rights reserved.
INotifyPropertyChanged
. Can't see any other way that you can do this, outside ofRx
, potentially. Don't worry too much about perf issues. In fact, you should be downloading the WPF profiling suite from the MSDN site and validating perf from that. Just going by the platitudes isn't going to cut it. – Expel