Beispiel #1
0
 internal void RaiseCollectionPathChanged(CollectionPathChangedEventArgs e)
 => CollectionChanged?.Invoke(this, e);
Beispiel #2
0
 private void OnTrackerCollectionChanged(object sender, CollectionPathChangedEventArgs e)
 {
     e.PropertyPath = ConstructPropertyPathForParent(e.PropertyPath);
     _parentTracker.RaiseCollectionPathChanged(e);
 }
        private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Reset:
                while (_itemTrackers.Any())
                {
                    RemoveTrackerAt(0);
                }

                Tracker.RaiseCollectionPathChanged(CollectionPathChangedEventArgs.CreateResetArgs());
                break;

            case NotifyCollectionChangedAction.Add:
                var index = (e.NewStartingIndex == -1) ? _itemTrackers.Count : e.NewStartingIndex;
                foreach (var item in e.NewItems)
                {
                    InsertTrackerAt(index++, item);
                }

                Tracker.RaiseCollectionPathChanged(new CollectionPathChangedEventArgs(CollectionPathChangedAction.Add, e.NewItems, e.NewStartingIndex));
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (var item in e.OldItems)
                {
                    RemoveTrackerOf(item);
                }

                Tracker.RaiseCollectionPathChanged(new CollectionPathChangedEventArgs(CollectionPathChangedAction.Remove, e.OldItems, e.OldStartingIndex));
                break;

            case NotifyCollectionChangedAction.Replace:
                // Remove old items...
                foreach (var item in e.OldItems)
                {
                    RemoveTrackerOf(item);
                }

                Tracker.RaiseCollectionPathChanged(new CollectionPathChangedEventArgs(CollectionPathChangedAction.Remove, e.OldItems, e.OldStartingIndex));

                // ...and insert replacement items
                var i = (e.NewStartingIndex == -1) ? _itemTrackers.Count : e.NewStartingIndex;
                foreach (var item in e.NewItems)
                {
                    InsertTrackerAt(i++, item);
                }

                Tracker.RaiseCollectionPathChanged(new CollectionPathChangedEventArgs(CollectionPathChangedAction.Add, e.NewItems, e.NewStartingIndex));
                break;

            case NotifyCollectionChangedAction.Move:
                // Remove items at old indices...
                foreach (var item in e.OldItems)
                {
                    RemoveTrackerOf(item);
                }

                Tracker.RaiseCollectionPathChanged(new CollectionPathChangedEventArgs(CollectionPathChangedAction.Remove, e.OldItems, e.OldStartingIndex));

                // ...and re-insert them at the new indices
                var i2 = e.NewStartingIndex;
                foreach (var item in e.NewItems)
                {
                    InsertTrackerAt(i2++, item);
                }

                Tracker.RaiseCollectionPathChanged(new CollectionPathChangedEventArgs(CollectionPathChangedAction.Add, e.NewItems, e.NewStartingIndex));
                break;
            }
        }