Exemplo n.º 1
0
        public void RemoveNode(Node node)
        {
            NodeRemoving?.Invoke(this, new RoutedEventArgs(NodeRemovingEvent, node));

            if (node == null)
            {
                return;
            }
            if (this._selectedNode == node)
            {
                this._selectedNode = null;
            }
            this.Children.Remove(node);

            foreach (Connector conn in node.Connectors)
            {
                //prevent 'collection changed' error
                HashSet <Connector> safeConnections = new HashSet <Connector>(conn.Connections);
                foreach (Connector other in safeConnections)
                {
                    if (conn.Mode == Connector.ConnectorMode.Input)
                    {
                        RemoveConnectionPath(other, conn);
                    }
                    else
                    {
                        RemoveConnectionPath(conn, other);
                    }
                    conn.Disconnect(other);
                }
            }
        }
            /// <summary>
            /// Removes a Node from the collection</summary>
            /// <param name="item">Node</param>
            /// <returns>True iff Node removed</returns>
            public bool Remove(Node item)
            {
                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                if (IsReadOnly)
                {
                    throw new InvalidOperationException("collection is read only");
                }

                if (item.HasChildren)
                {
                    item.Nodes.Clear();
                }

                NodeRemoving.Raise(this, new NodeEventArgs(item));

                return(m_nodes.Remove(item));
            }