Exemplo n.º 1
0
        public NodeViewModel CreateNode(NodeViewModel node, bool centerNode)
        {
            if (centerNode)
            {
                //
                // We want to center the node.
                //
                // For this to happen we need to wait until the UI has determined the
                // size based on the node's data-template.
                //
                // So we define an anonymous method to handle the SizeChanged event for a node.
                //
                // Note: If you don't declare sizeChangedEventHandler before initializing it you will get
                //       an error when you try and unsubscribe the event from within the event handler.
                //
                EventHandler<EventArgs> sizeChangedEventHandler = null;
                sizeChangedEventHandler =
                    delegate (object sender, EventArgs e)
                    {
                        //
                        // This event handler will be called after the size of the node has been determined.
                        // So we can now use the size of the node to modify its position.
                        //
                        node.X -= node.Size.Width / 2;
                        node.Y -= node.Size.Height / 2;

                        //
                        // Don't forget to unhook the event, after the initial centering of the node
                        // we don't need to be notified again of any size changes.
                        //
                        node.SizeChanged -= sizeChangedEventHandler;
                    };

                //
                // Now we hook the SizeChanged event so the anonymous method is called later
                // when the size of the node has actually been determined.
                //
                node.SizeChanged += sizeChangedEventHandler;
            }

            //
            // Add the node to the view-model.
            //
            this.Network.Nodes.Add(node);

            return node;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Delete the node from the view-model.
        /// Also deletes any connections to or from the node.
        /// </summary>
        public void DeleteNode(NodeViewModel node)
        {
            //
            // Remove all connections attached to the node.
            //
            this.Network.ExecutionConnections.RemoveRange(node.AttachedExecutionConnections);

            //
            // Remove all connections attached to the node.
            //
            this.Network.Connections.RemoveRange(node.AttachedConnections);

            //
            // Remove the node from the network.
            //
            this.Network.Nodes.Remove(node);
        }
Exemplo n.º 3
0
        private void CreateNode(NodeViewModel node, /*Point nodeLocation,*/ bool centerNode)
        {
            //cmMenu.PlacementRectangle.TopLeft
            //var nodeLocation = Mouse.GetPosition(networkControl);
            //var nodeLocation = networkControl.PointFromScreen(cmMenu.PointToScreen(new Point(0, 0)));

            //node.X = nodeLocation.X;
            //node.Y = nodeLocation.Y;

            this.ViewModel.CreateNode(node, centerNode);


            {
                var target = NodeCreated;
                if (target != null)
                {
                    target(this, new NodeCreatedEventArgs() { Node = node });
                }
            }
        }