예제 #1
0
        /// <summary>
        /// Event raised when the user has started to drag out a connection.
        /// </summary>
        private void networkControl_ExecutionConnectionDragStarted(object sender, ExecutionConnectionDragStartedEventArgs e)
        {
            var draggedOutConnector = (ExecutionConnectorViewModel)e.ExecutionConnectorDraggedOut;
            var curDragPoint = Mouse.GetPosition(networkControl);

            //
            // Delegate the real work to the view model.
            //
            var connection = this.ViewModel.ExecutionConnectionDragStarted(draggedOutConnector, curDragPoint);

            //
            // Must return the view-model object that represents the connection via the event args.
            // This is so that NetworkView can keep track of the object while it is being dragged.
            //
            e.ExecutionConnection = connection;
        }
        /// <summary>
        /// Event raised when the user starts to drag a connector.
        /// </summary>
        private void ExecutionConnectorItem_DragStarted(object source, ExecutionConnectorItemDragStartedEventArgs e)
        {
            this.Focus();

            e.Handled = true;

            this.IsDragging = true;
            this.IsNotDragging = false;
            this.IsDraggingExecutionConnection = true;
            this.IsNotDraggingExecutionConnection = false;

            this.draggedOutExecutionConnectorItem = (ExecutionConnectorItem)e.OriginalSource;
            var nodeItem = this.draggedOutExecutionConnectorItem.ParentNodeItem;
            this.draggedOutNodeDataContext = nodeItem.DataContext != null ? nodeItem.DataContext : nodeItem;
            this.draggedOutExecutionConnectorDataContext = this.draggedOutExecutionConnectorItem.DataContext != null ? this.draggedOutExecutionConnectorItem.DataContext : this.draggedOutExecutionConnectorItem;

            //
            // Raise an event so that application code can create a connection and
            // add it to the view-model.
            //
            ExecutionConnectionDragStartedEventArgs eventArgs = new ExecutionConnectionDragStartedEventArgs(ExecutionConnectionDragStartedEvent, this, this.draggedOutNodeDataContext, this.draggedOutExecutionConnectorDataContext);
            RaiseEvent(eventArgs);

            //
            // Retrieve the the view-model object for the connection was created by application code.
            //
            this.draggingExecutionConnectionDataContext = eventArgs.ExecutionConnection;

            if (draggingExecutionConnectionDataContext == null)
            {
                //
                // Application code didn't create any connection.
                //
                e.Cancel = true;
                return;
            }
        }