/// <summary> /// Synchronizes the logical tree. /// </summary> /// <param name="e">The <see cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs" /> instance containing the event data.</param> private void SyncLogicalTree(NotifyCollectionChangedEventArgs e) { // In order to get DataContext and binding to work with the series, axes and annotations // we add the items to the logical tree if (e.NewItems != null) { foreach (var item in e.NewItems.OfType <ISetLogicalParent>()) { item.SetParent(this); } LogicalChildren.AddRange(e.NewItems.OfType <ILogical>()); VisualChildren.AddRange(e.NewItems.OfType <IVisual>()); } if (e.OldItems != null) { foreach (var item in e.OldItems.OfType <ISetLogicalParent>()) { item.SetParent(null); } foreach (var item in e.OldItems) { LogicalChildren.Remove((ILogical)item); VisualChildren.Remove((IVisual)item); } } }
/// <summary> /// Called when new containers are materialized for the <see cref="ItemsControl"/> by its /// <see cref="ItemContainerGenerator"/>. /// </summary> /// <param name="e">The details of the containers.</param> protected virtual void OnContainersMaterialized(ItemContainerEventArgs e) { var toAdd = new List <ILogical>(); foreach (var container in e.Containers) { // If the item is its own container, then it will be added to the logical tree when // it was added to the Items collection. if (container.ContainerControl != null && container.ContainerControl != container.Item) { toAdd.Add(container.ContainerControl); } } LogicalChildren.AddRange(toAdd); }
/// <summary> /// Given a collection of items, adds those that are controls to the logical children. /// </summary> /// <param name="items">The items.</param> private void AddControlItemsToLogicalChildren(IEnumerable items) { var toAdd = new List <ILogical>(); if (items != null) { foreach (var i in items) { var control = i as IControl; if (control != null && !LogicalChildren.Contains(control)) { toAdd.Add(control); } } } LogicalChildren.AddRange(toAdd); }