in src/Microsoft.Xaml.Behaviors/AttachableCollection.cs [96:164]
private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
{
// We fix the snapshot to mirror the structure, even if an exception is thrown. This may not be desirable.
case NotifyCollectionChangedAction.Add:
foreach (T item in e.NewItems)
{
try
{
this.VerifyAdd(item);
this.ItemAdded(item);
}
finally
{
this.snapshot.Insert(this.IndexOf(item), item);
}
}
break;
case NotifyCollectionChangedAction.Replace:
foreach (T item in e.OldItems)
{
this.ItemRemoved(item);
this.snapshot.Remove(item);
}
foreach (T item in e.NewItems)
{
try
{
this.VerifyAdd(item);
this.ItemAdded(item);
}
finally
{
this.snapshot.Insert(this.IndexOf(item), item);
}
}
break;
case NotifyCollectionChangedAction.Remove:
foreach (T item in e.OldItems)
{
this.ItemRemoved(item);
this.snapshot.Remove(item);
}
break;
case NotifyCollectionChangedAction.Reset:
foreach (T item in this.snapshot)
{
this.ItemRemoved(item);
}
this.snapshot = new Collection<T>();
foreach (T item in this)
{
this.VerifyAdd(item);
this.ItemAdded(item);
}
break;
case NotifyCollectionChangedAction.Move:
default:
Debug.Fail("Unsupported collection operation attempted.");
break;
}
#if DEBUG
this.VerifySnapshotIntegrity();
#endif
}