I want to monitor changes to a CollectionView but the CollectionChanged event is protected. How should I do this? Surely there must be a way to subscribe to this event - the list controls must do this somehow.
I can cast SourceCollection to INotifyCollectionChanged and add an event there, but that seems unneccesarily messy.
... the list controls must do this somehow.
I can cast SourceCollection to INotifyCollectionChanged and add an event there, but that seems unneccesarily messy.
In fact, that's exactly how the list controls do it. This is from ItemsControl's source code (found via http://www.dotnetframework.org/):
((INotifyCollectionChanged)_items).CollectionChanged += new NotifyCollectionChangedEventHandler(OnItemCollectionChanged);
You are probably meant to expose your CollectionViews as the interface, ICollectionView, which itself inherits INotifyCollectionChanged as well as providing CollectionView properties like CurrentItem.
Why aren't you using an ObservableCollection instead?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With