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 GridChild(uielement); AddVisualChild(child); children.Insert(index, child); 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); index++; } } if (e.Action == NotifyCollectionChangedAction.Replace) { var index = e.NewStartingIndex; foreach (var uielement in e.NewItems.Cast <UIElement>()) { var child = new GridChild(uielement); RemoveVisualChild(children [index]); AddVisualChild(child); children [index] = child; index++; } } if (e.Action == NotifyCollectionChangedAction.Reset) { 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 GridChild (uielement); AddVisualChild (child); children.Insert (index, child); 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); index++; } } if (e.Action == NotifyCollectionChangedAction.Replace) { var index = e.NewStartingIndex; foreach (var uielement in e.NewItems.Cast<UIElement>()) { var child = new GridChild (uielement); RemoveVisualChild (children [index]); AddVisualChild (child); children [index] = child; index++; } } if (e.Action == NotifyCollectionChangedAction.Reset) { children.Clear (); } }