2

My viewmodel has two Collections, one is MainCollection and other is DerivedCollection. They are displayed using a control, so that when user interacts with the mouse, items can be added or removed from MainCollection, and DerivedCollection should be refreshed accordingly.

The first part (updating MainCollection) happens automatically via data-binding, but I don' know how can I hook RefreshDerivedCollection method to MainCollection.PropertyChanged event.

Both collections and the method live in the same viewmodel.

heltonbiker
  • 26,657
  • 28
  • 137
  • 252

1 Answers1

4

You can subscribe to MainCollection.CollectionChanged and refresh derived collection there:

MainCollection.CollectionChanged += this.OnMainCollectionChanged;

and

void OnMainCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
    // TODO: Handle main collection change here.
}
Anatolii Gabuza
  • 6,184
  • 2
  • 36
  • 54
  • Well, that's what I tried to do, but missed the `CollectionChanged` event among so many other properties in intellisense... :P Thanks! – heltonbiker Jan 20 '14 at 13:08