Exemple #1
0
        protected override NotifyCollectionChangedEventArgs BuildCompositeEventArgs(IReadOnlyObservableList <T> sender, NotifyCollectionChangedEventArgs e)
        {
            int GetSenderStartIndex() => ObservableCollections.TakeWhile(x => x != sender).Sum(x => x.Count);
            int GetNewItemsIndex() => GetSenderStartIndex() + (e.NewStartingIndex >= 0 ? e.NewStartingIndex : throw new InvalidOperationException());
            int GetOldItemsIndex() => GetSenderStartIndex() + (e.OldStartingIndex >= 0 ? e.OldStartingIndex : throw new InvalidOperationException());

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                return(CollectionChangedEventArgs.InsertRange(e.NewItems, GetNewItemsIndex()));
            }

            case NotifyCollectionChangedAction.Remove:
            {
                return(CollectionChangedEventArgs.RemoveRange(e.OldItems, GetOldItemsIndex()));
            }

            case NotifyCollectionChangedAction.Replace:
            {
                return(CollectionChangedEventArgs.ReplaceRange(e.OldItems, e.NewItems, GetOldItemsIndex()));
            }

            case NotifyCollectionChangedAction.Move:
            {
                return(CollectionChangedEventArgs.MoveRange(e.OldItems, GetOldItemsIndex(), GetNewItemsIndex()));
            }

            case NotifyCollectionChangedAction.Reset:
            {
                if (sender.Count == Count)
                {
                    return(CollectionChangedEventArgs.Clear());
                }

                return(CollectionChangedEventArgs.RemoveRange(sender.ToList(), GetSenderStartIndex()));
            }

            default:
                throw new NotSupportedException();
            }
        }
Exemple #2
0
 public MyMessage(ObservableCollections col1, ObservableCollections col2, ObservableCollections col3)
 {
    this.Col1 = col1;
    this.Col2 = col2;
    this.Col3 = col3;
  }