/// <summary> /// Handles the CollectionChanged event of the ChildNodes control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="NotifyCollectionChangedEventArgs"/> instance containing the event data.</param> private void ChildNodes_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (var node in e.NewItems.OfType <INode>()) { var control = new NodeContainerControl(node); m_nodesSet.Add(node, control); Children.Add(control); } break; case NotifyCollectionChangedAction.Remove: var toRemove = m_nodesSet.Where(n => e.OldItems.Contains(n.Key)).ToList(); foreach (var pair in toRemove) { m_nodesSet.Remove(pair.Key); Children.Remove(pair.Value); } break; case NotifyCollectionChangedAction.Reset: Children.Clear(); m_nodesSet.Clear(); m_selectedNodes.Clear(); break; } }
/// <summary> /// Adds the existing nodes. /// </summary> private void AddExistingNodes() { foreach (var node in m_diagram.ChildNodes) { var control = new NodeContainerControl(node); m_nodesSet.Add(node, control); Children.Add(control); } }