in src/BehaviorsSDKManaged/Microsoft.Xaml.Interactivity/BehaviorCollection.cs [87:151]
private void BehaviorCollection_VectorChanged(IObservableVector<DependencyObject> sender, IVectorChangedEventArgs eventArgs)
{
if (eventArgs.CollectionChange == CollectionChange.Reset)
{
foreach (IBehavior behavior in this._oldCollection)
{
if (behavior.AssociatedObject != null)
{
behavior.Detach();
}
}
this._oldCollection.Clear();
foreach (DependencyObject newItem in this)
{
this._oldCollection.Add(this.VerifiedAttach(newItem));
}
#if DEBUG
this.VerifyOldCollectionIntegrity();
#endif
return;
}
int eventIndex = (int)eventArgs.Index;
DependencyObject changedItem = this[eventIndex];
switch (eventArgs.CollectionChange)
{
case CollectionChange.ItemInserted:
this._oldCollection.Insert(eventIndex, this.VerifiedAttach(changedItem));
break;
case CollectionChange.ItemChanged:
IBehavior oldItem = this._oldCollection[eventIndex];
if (oldItem.AssociatedObject != null)
{
oldItem.Detach();
}
this._oldCollection[eventIndex] = this.VerifiedAttach(changedItem);
break;
case CollectionChange.ItemRemoved:
oldItem = this._oldCollection[eventIndex];
if (oldItem.AssociatedObject != null)
{
oldItem.Detach();
}
this._oldCollection.RemoveAt(eventIndex);
break;
default:
Debug.Assert(false, "Unsupported collection operation attempted.");
break;
}
#if DEBUG
this.VerifyOldCollectionIntegrity();
#endif
}