protected static bool TryInsert(BulkUpdateableCollection <T> collection, IReadOnlyList <T> items) { if (items.Count > collection.Count && collection.Count > 0) { var si = 0; foreach (var ce in collection) { var found = false; for (var i = si; i < items.Count; i++) { if (items[i] == ce) { si = i + 1; found = true; break; } } if (!found) { return(false); } } for (var i = 0; i < items.Count; i++) { var e = items[i]; if (collection.ElementAtOrDefault(i) != e) { collection.Insert(i, e); } } return(true); } return(false); }
protected static bool TryRemove(BulkUpdateableCollection <T> collection, IReadOnlyList <T> items) { if (0 < items.Count && items.Count < collection.Count) { var si = 0; foreach (var e in items) { var found = false; for (var i = si; i < collection.Count; i++) { if (collection[i] == e) { si = i + 1; found = true; break; } } if (!found) { return(false); } } for (var i = collection.Count - 1; i >= 0; i--) { if (collection[i] != items.ElementAtOrDefault(items.Count - collection.Count + i)) { collection.RemoveAt(i); } } return(true); } return(false); }
public MenuPageItemViewModel(MenuPageGroupViewModel group, CommandViewModelBase command, bool isExtension = false) { Group = group; Command = command; SubCommands = new BulkUpdateableCollection <CommandViewModelBase>(); IsExtension = isExtension; Command.PropertyChanged += Command_PropertyChanged; }
protected override void OnReplace(BulkUpdateableCollection <T> collection, IReadOnlyList <T> items) { collection.Items.Clear(); foreach (var e in items) { collection.Items.Add(e); } collection.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); }
public InteractionServiceWindowViewModel(InteractionService interaction) { interaction.RegisterModal(typeof(CalculatorModalViewModel), vm => new CalculatorControl() { DataContext = vm }); Interaction = interaction; Logs = new BulkUpdateableCollection <LogViewModel>(); BindingOperations.EnableCollectionSynchronization(Logs, ((ICollection)Logs).SyncRoot); }
protected virtual void OnReplace(BulkUpdateableCollection <T> collection, IReadOnlyList <T> items) { if (TryInsert(collection, items) || TryRemove(collection, items)) { return; } collection.Clear(); foreach (var e in items) { collection.Add(e); } }
public virtual int RemoveAll(BulkUpdateableCollection <T> collection, Func <T, bool> predicate) { lock (((ICollection)collection).SyncRoot) { var c = 0; for (var i = collection.Count - 1; i >= 0; i--) { if (predicate(collection[i])) { collection.RemoveAt(i); c++; } } return(c); } }
public void Set(BulkUpdateableCollection <T> collection, IEnumerable <T> items) { if (items != collection) { lock (((ICollection)collection).SyncRoot) { var list = items as IReadOnlyList <T> ?? items?.ToList(); if (list?.Count > 0) { OnReplace(collection, list); } else if (collection.Items.Any()) { OnClear(collection); } } } }
public override int RemoveAll(BulkUpdateableCollection <T> collection, Func <T, bool> predicate) { lock (((ICollection)collection).SyncRoot) { var c = 0; for (var i = collection.Count - 1; i >= 0; i--) { if (predicate(collection[i])) { collection.Items.RemoveAt(i); c++; } } if (c > 0) { collection.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } return(c); } }
public ObjectValidator(object target, bool useExpressionBinding = false) { Target = target; ValidationResults = new BulkUpdateableCollection <ValidationResult>(); UseExpressionBinding = useExpressionBinding; }
protected override void OnClear(BulkUpdateableCollection <T> collection) { collection.Clear(); collection.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); }
protected virtual void OnClear(BulkUpdateableCollection <T> collection) => collection.Clear();
public MenuPageGroupViewModel(string title) { Title = title; Items = new BulkUpdateableCollection <MenuPageItemViewModel>(); }
public EntitySelectorComboBox() { _Items = new BulkUpdateableCollection <Item>(); DataContextChanged += EntitySelectorComboBox_DataContextChanged; }