private void _coreCollection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { switch (e.Action) { case System.Collections.Specialized.NotifyCollectionChangedAction.Add: if (CollectionGroups?.Count > 0) { foreach (var item in CollectionGroups.OfType <SelfServiceDependencyCollectionViewGroupBase>()) { e.NewItems?.OfType <object>().ToList().Select(x => item?.TryAddItemToGroup(x)).ToArray(); } e.NewItems?.OfType <object>().ToList().Select(x => GroupingManager?.TryAddItemToGroup(x)).ToArray(); } RefreshPositionValues(); break; case System.Collections.Specialized.NotifyCollectionChangedAction.Move: break; case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: if (CollectionGroups?.Count > 0) { foreach (var item in CollectionGroups.OfType <SelfServiceDependencyCollectionViewGroupBase>()) { e.OldItems?.OfType <object>().ToList().Select(x => item?.TryRemoveItemFromGroup(x)).Any(); } e.NewItems?.OfType <object>().ToList().Select(x => GroupingManager?.TryRemoveItemFromGroup(x)).ToArray(); } RefreshPositionValues(); break; case System.Collections.Specialized.NotifyCollectionChangedAction.Replace: break; case System.Collections.Specialized.NotifyCollectionChangedAction.Reset: if (CollectionGroups?.Count > 0) { foreach (ICollectionViewGroup item in CollectionGroups) { item.GroupItems?.Clear(); } } RefreshPositionValues(); break; default: break; } }
private void OnCollectionChangedUpdateGroups(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: for (int i = e.NewStartingIndex; i < e.NewStartingIndex + e.NewItems.Count; i++) { CollectionGroups.Insert(i, new CollectionViewGroup(_collection.ElementAt(i), _itemsPath)); } break; case NotifyCollectionChangedAction.Move: for (int i = e.OldStartingIndex + e.OldItems.Count - 1; i >= e.OldStartingIndex; i--) { //TODO: Untested. This may be incorrect if OldItems.Count > 1. var group = CollectionGroups[i]; CollectionGroups.RemoveAt(i); CollectionGroups.Insert(i, group); } break; case NotifyCollectionChangedAction.Remove: for (int i = e.OldStartingIndex + e.OldItems.Count - 1; i >= e.OldStartingIndex; i--) { CollectionGroups.RemoveAt(i); } break; case NotifyCollectionChangedAction.Replace: for (int i = e.NewStartingIndex; i < e.NewStartingIndex + e.NewItems.Count; i++) { CollectionGroups[i] = new CollectionViewGroup(_collection.ElementAt(i), _itemsPath); } break; case NotifyCollectionChangedAction.Reset: CollectionGroups.Clear(); break; } }