private void HandleCollectionChanged (object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { var index = e.NewStartingIndex; foreach (var uielement in e.NewItems.Cast<UIElement>()) { var child = new CanvasChild (uielement); AddVisualChild (child); children.Insert (index, child); RaiseAddedItem (uielement); index++; } } if (e.Action == NotifyCollectionChangedAction.Remove) { var index = e.OldStartingIndex; foreach (var uielement in e.OldItems.Cast<UIElement>()) { var child = children [index]; RemoveVisualChild (child); children.Remove (child); RaiseRemovedItem (uielement); index++; } } if (e.Action == NotifyCollectionChangedAction.Replace) { var index = e.NewStartingIndex; foreach (var uielement in e.NewItems.Cast<UIElement>()) { var child = new CanvasChild (uielement); RemoveVisualChild (children [index]); RaiseRemovedItem (children [index].Content); AddVisualChild (child); children [index] = child; RaiseAddedItem (uielement); index++; } } if (e.Action == NotifyCollectionChangedAction.Reset) { foreach (var child in children) { RaiseRemovedItem (child.Content); } children.Clear (); } }
private void HandleCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { var index = e.NewStartingIndex; foreach (var uielement in e.NewItems.Cast <UIElement>()) { var child = new CanvasChild(uielement); AddVisualChild(child); children.Insert(index, child); RaiseAddedItem(uielement); index++; } } if (e.Action == NotifyCollectionChangedAction.Remove) { var index = e.OldStartingIndex; foreach (var uielement in e.OldItems.Cast <UIElement>()) { var child = children [index]; RemoveVisualChild(child); children.Remove(child); RaiseRemovedItem(uielement); index++; } } if (e.Action == NotifyCollectionChangedAction.Replace) { var index = e.NewStartingIndex; foreach (var uielement in e.NewItems.Cast <UIElement>()) { var child = new CanvasChild(uielement); RemoveVisualChild(children [index]); RaiseRemovedItem(children [index].Content); AddVisualChild(child); children [index] = child; RaiseAddedItem(uielement); index++; } } if (e.Action == NotifyCollectionChangedAction.Reset) { foreach (var child in children) { RaiseRemovedItem(child.Content); } children.Clear(); } }