private void UpdateItem(OrderedListInternal <int, T> filterCollection, NotifyCollectionChangedEventArgs e, NotificationType notificationType) { int filterIndex; switch (e.Action) { case NotifyCollectionChangedAction.Add: var item = (T)e.NewItems[0]; UpdateFilterItems(filterCollection, e.NewStartingIndex, 1); if (!_filter(item)) { return; } filterIndex = filterCollection.Add(e.NewStartingIndex, item); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, filterIndex), notificationType); break; case NotifyCollectionChangedAction.Remove: filterIndex = filterCollection.IndexOfKey(e.OldStartingIndex); UpdateFilterItems(filterCollection, e.OldStartingIndex, -1); if (filterIndex == -1) { return; } filterCollection.RemoveAt(filterIndex); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, e.OldItems[0], filterIndex), notificationType); break; case NotifyCollectionChangedAction.Replace: filterIndex = filterCollection.IndexOfKey(e.NewStartingIndex); if (filterIndex == -1) { return; } var newItem = (T)e.NewItems[0]; if (_filter(newItem)) { T oldItem = filterCollection.GetValue(filterIndex); filterCollection.Values[filterIndex] = newItem; OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, e.NewItems[0], oldItem, filterIndex), notificationType); } else { T oldValue = filterCollection.GetValue(filterIndex); filterCollection.RemoveAt(filterIndex); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, oldValue, filterIndex), notificationType); } break; default: UpdateFilterInternal(filterCollection, _filter, notificationType); break; } }
private void UpdateItem(NotifyCollectionChangedEventArgs e, out bool shouldRaiseEvents) { shouldRaiseEvents = false; int filterIndex; switch (e.Action) { case NotifyCollectionChangedAction.Add: var item = (T)e.NewItems[0]; UpdateFilterItems(e.NewStartingIndex, 1); if (!_filter(item)) { return; } filterIndex = _filterCollection.Add(e.NewStartingIndex, item); EventsTracker.AddEvent(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, filterIndex)); shouldRaiseEvents = true; break; case NotifyCollectionChangedAction.Remove: filterIndex = _filterCollection.IndexOfKey(e.OldStartingIndex); UpdateFilterItems(e.OldStartingIndex, -1); if (filterIndex == -1) { return; } _filterCollection.RemoveAt(filterIndex); EventsTracker.AddEvent(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, e.OldItems[0], filterIndex)); shouldRaiseEvents = true; break; case NotifyCollectionChangedAction.Replace: filterIndex = _filterCollection.IndexOfKey(e.NewStartingIndex); if (filterIndex == -1) { return; } var newItem = (T)e.NewItems[0]; if (_filter(newItem)) { T oldItem = _filterCollection.GetValue(filterIndex); _filterCollection.Values[filterIndex] = newItem; EventsTracker.AddEvent( new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, e.NewItems[0], oldItem, filterIndex)); } else { T oldValue = _filterCollection.GetValue(filterIndex); _filterCollection.RemoveAt(filterIndex); EventsTracker.AddEvent(new NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction.Remove, oldValue, filterIndex)); } shouldRaiseEvents = true; break; case NotifyCollectionChangedAction.Reset: UpdateFilterInternal(out shouldRaiseEvents); break; default: //For Move support. if (e.Action.ToString("G") != "Move") { break; } var movedItem = (T)e.NewItems[0]; filterIndex = _filterCollection.IndexOfKey(e.OldStartingIndex); UpdateFilterItems(e.OldStartingIndex, -1); UpdateFilterItems(e.NewStartingIndex, 1); if (filterIndex == -1 || !_filter(movedItem)) { return; } _filterCollection.RemoveAt(filterIndex); var newIndex = _filterCollection.Add(e.NewStartingIndex, movedItem); EventsTracker.AddEvent(new NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction.Remove, e.OldItems[0], filterIndex)); EventsTracker.AddEvent(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, movedItem, newIndex)); shouldRaiseEvents = true; break; } }