Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is CollectionView.CollectionChanged protected?

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.

like image 715
Grokys Avatar asked Jun 11 '09 23:06

Grokys


2 Answers

... 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.

like image 195
nmclean Avatar answered Nov 07 '22 00:11

nmclean


Why aren't you using an ObservableCollection instead?

like image 32
Jason Watts Avatar answered Nov 07 '22 00:11

Jason Watts