public void MultipleActionsWithoutSuspendingNotifications() { var counter = 0; var fastCollection = new FastObservableCollection <int>(); fastCollection.AutomaticallyDispatchChangeNotifications = false; fastCollection.CollectionChanged += (sender, e) => counter++; fastCollection.Add(0); fastCollection.Add(1); fastCollection.Remove(0); fastCollection.Remove(1); fastCollection.AddRange(new[] { 1, 2 }); fastCollection[0] = 5; fastCollection.Move(0, 1); fastCollection.Clear(); Assert.AreEqual(9, counter); }
public void RemovingItemsInRemovingMode() { var counter = 0; var eventArgs = (NotifyCollectionChangedEventArgs)null; var fastCollection = new FastObservableCollection <int> { 1, 2, 3, 4, 5 }; fastCollection.AutomaticallyDispatchChangeNotifications = false; fastCollection.CollectionChanged += (sender, e) => { counter++; eventArgs = e; }; using (fastCollection.SuspendChangeNotifications(SuspensionMode.Removing)) { fastCollection.Remove(1); fastCollection.Remove(2); fastCollection.Remove(3); fastCollection.Remove(4); fastCollection.Remove(5); } Assert.AreEqual(1, counter); Assert.AreEqual(NotifyCollectionChangedAction.Remove, eventArgs.Action); CollectionAssert.AreEqual(eventArgs.OldItems, new[] { 1, 2, 3, 4, 5 }); }
public void SuspendsValidationWhileAddingAndRemovingItems() { var counter = 0; var fastCollection = new FastObservableCollection <int>(); fastCollection.AutomaticallyDispatchChangeNotifications = false; fastCollection.CollectionChanged += (sender, e) => counter++; using (fastCollection.SuspendChangeNotifications()) { fastCollection.Add(1); fastCollection.Add(2); fastCollection.Add(3); fastCollection.Add(4); fastCollection.Add(5); fastCollection.Remove(5); fastCollection.Remove(4); fastCollection.Remove(3); fastCollection.Remove(2); fastCollection.Remove(1); } Assert.AreEqual(0, counter); }
/// <summary> /// Updates the entries (via Remove and Add) in the ALL items collection /// with the entries in the <param name="viewModels"/> array parameter. /// </summary> /// <param name="viewModels"></param> private void UpdateAllEntries(params VM[] viewModels) { Logger.InfoFormat("_"); _All.SuspendCollectionChangeNotification(); try { var removeItems = _All.Where(vm => !viewModels.Contains(vm)).ToList(); var addItems = viewModels.Where(vm => !_All.Contains(vm)).ToList(); foreach (var vm in removeItems) { _All.Remove(vm); } foreach (var vm in addItems) { _All.Add(vm); } } finally { _All.NotifyChanges(); if (this.EntriesChanged != null) { this.EntriesChanged(this, EventArgs.Empty); } } }
private void updateEntries(params VM[] viewModels) { FastObservableCollection <VM> all = All as FastObservableCollection <VM>; all.SuspendCollectionChangeNotification(); var removeItems = all.Where(vm => !viewModels.Contains(vm)).ToList(); var addItems = viewModels.Where(vm => !all.Contains(vm)).ToList(); if (addItems.Count == 0 && removeItems.Count == 0) { return; //nothing to do here } foreach (var vm in removeItems) { all.Remove(vm); } foreach (var vm in addItems) { all.Add(vm); } _subItemList = all.ToArray().ToList(); all.NotifyChanges(); EntriesChanged?.Invoke(this, EventArgs.Empty); }
private void updateEntries(params VM[] viewModels) { FastObservableCollection <VM> all = All as FastObservableCollection <VM>; all.SuspendCollectionChangeNotification(); var removeItems = all.Where(vm => !viewModels.Contains(vm)).ToList(); var addItems = viewModels.Where(vm => !all.Contains(vm)).ToList(); foreach (var vm in removeItems) { all.Remove(vm); } foreach (var vm in addItems) { all.Add(vm); } _subItemList = all.ToArray().ToList(); all.NotifyChanges(); if (EntriesChanged != null) { EntriesChanged(this, EventArgs.Empty); } }
public static void MoveItemToTop <T>(this FastObservableCollection <T> collection, T item) { using (collection.SuspendChangeNotifications()) { collection.Remove(item); collection.Insert(0, item); } }
public void ThrowsInvalidOperationExceptionForRemovingInAddingMode() { var fastCollection = new FastObservableCollection <int> { 0 }; using (fastCollection.SuspendChangeNotifications(SuspensionMode.Adding)) { Assert.Throws <InvalidOperationException>(() => fastCollection.Remove(0)); } }
public void SuspendsValidationWhileAddingAndRemovingItems() { int counter = 0; var fastCollection = new FastObservableCollection<int>(); fastCollection.AutomaticallyDispatchChangeNotifications = false; fastCollection.CollectionChanged += (sender, e) => counter++; using (fastCollection.SuspendChangeNotifications()) { fastCollection.Add(1); fastCollection.Add(2); fastCollection.Add(3); fastCollection.Add(4); fastCollection.Add(5); fastCollection.Remove(5); fastCollection.Remove(4); fastCollection.Remove(3); fastCollection.Remove(2); fastCollection.Remove(1); } Assert.AreEqual(1, counter); }