private void SourceCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: AddItems(e.NewItems?.Cast <T>()); break; case NotifyCollectionChangedAction.Remove: RemoveItems(e.OldItems?.Cast <T>()); break; case NotifyCollectionChangedAction.Reset: WeakEvents.Unsubscribe(this); Items.Clear(); AttachCollectionEvents((INotifyCollectionChanged)sender); break; case NotifyCollectionChangedAction.Replace: RemoveItems(e.OldItems?.Cast <T>()); AddItems(e.NewItems?.Cast <T>()); break; case NotifyCollectionChangedAction.Move: break; default: throw new NotImplementedException("Source action not supported"); } }
public void UnsubscribeAll() { WeakEvents.Unsubscribe(this); }