/// <inheritdoc /> public void Clear() { ViewModels.Clear(); EncapsulatedList.Clear(); OnAllPropertiesChanged(); CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); ClearItemCsommand.OnCanExecuteChanged(); RemoveItemCommand.OnCanExecuteChanged(); }
public void Insert(int index, TViewModel item) { if (ViewModels.Contains(item) || EncapsulatedList.Contains(item?.Model)) { throw new NotSupportedException("The item was already added to the collection"); } ViewModels.Insert(index, item); EncapsulatedList.Insert(index, item?.Model); CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index)); ClearItemCsommand.OnCanExecuteChanged(); RemoveItemCommand.OnCanExecuteChanged(); OnAllPropertiesChanged(); }
/// <inheritdoc /> public bool Remove(TViewModel item) { int index = ViewModels.IndexOf(item); bool returnValue = ViewModels.Remove(item); EncapsulatedList.Remove(item?.Model); CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index)); ClearItemCsommand.OnCanExecuteChanged(); RemoveItemCommand.OnCanExecuteChanged(); OnAllPropertiesChanged(); return(returnValue); }
/// <inheritdoc /> public void Add(TViewModel item) { if (ViewModels.Contains(item) || EncapsulatedList.Any(i => ReferenceEquals(i, item?.Model))) { throw new NotSupportedException("The item was already added to the collection"); } ViewModels.Add(item); EncapsulatedList.Add(item?.Model); CollectionChanged?.Invoke(ViewModels, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item)); OnAllPropertiesChanged(); ClearItemCsommand.OnCanExecuteChanged(); RemoveItemCommand.OnCanExecuteChanged(); }