void MVVMItemsControlBase_CollectionChanged(object sender, MVVMNotifyCollectionChangedEventArgs e) { switch (e.Action) { case MVVMNotifyCollectionChangedAction.Add: Insert(e.NewStartingIndex, e.NewItems[0]); break; case MVVMNotifyCollectionChangedAction.Remove: RemoveAt(e.OldStartingIndex); break; case MVVMNotifyCollectionChangedAction.Replace: Replace(e.OldStartingIndex, e.NewItems[0]); break; case MVVMNotifyCollectionChangedAction.Move: Move(e.OldStartingIndex, e.NewStartingIndex); break; case MVVMNotifyCollectionChangedAction.Reset: Reset(); break; default: throw new NotImplementedException(e.Action.ToString()); } }
/// <summary> /// Raise CollectionChanged event to any listeners. /// Properties/methods modifying this ObservableCollection will raise /// a collection changed event through this virtual method. /// </summary> /// <remarks> /// When overriding this method, either call its base implementation /// or call <see cref="BlockReentrancy"/> to guard against reentrant collection changes. /// </remarks> protected virtual void OnCollectionChanged(MVVMNotifyCollectionChangedEventArgs e) { if (CollectionChanged != null) { using (BlockReentrancy()) { CollectionChanged(this, e); } } }