/// <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;
            }
        }
        /// <summary>
        /// Event raised when the user has finished dragging a connector.
        /// </summary>
        private void ConnectorItem_DragCompleted(object source, ConnectorItemDragCompletedEventArgs e)
        {
            e.Handled = true;

            Trace.Assert((ConnectorItem)e.OriginalSource == this.draggedOutConnectorItem);

            Point mousePoint = Mouse.GetPosition(this);

            //
            // Figure out if the end of the connection was dropped on a connector.
            //
            ConnectorItem connectorDraggedOver = null;
            object connectorDataContextDraggedOver = null;
            DetermineConnectorItemDraggedOver(mousePoint, out connectorDraggedOver, out connectorDataContextDraggedOver);

            //
            // Now that connection dragging has completed, don't any feedback adorner.
            //
            ClearFeedbackAdorner();

            //
            // Raise an event to inform application code that connection dragging is complete.
            // The application code can determine if the connection between the two connectors
            // is valid and if so it is free to make the appropriate connection in the view-model.
            //
            RaiseEvent(new ConnectionDragCompletedEventArgs(ConnectionDragCompletedEvent, this, this.draggedOutNodeDataContext, this.draggingConnectionDataContext, this.draggedOutConnectorDataContext, connectorDataContextDraggedOver));

            this.IsDragging = false;
            this.IsNotDragging = true;
            this.IsDraggingExecutionConnection = false;
            this.IsDraggingConnection = false;
            this.IsNotDraggingExecutionConnection = true;
            this.IsNotDraggingConnection = true;
            this.draggedOutExecutionConnectorDataContext = null;
            this.draggedOutConnectorDataContext = null;
            this.draggedOutNodeDataContext = null;
            this.draggedOutExecutionConnectorItem = null;
            this.draggedOutConnectorItem = null;
            this.draggingExecutionConnectionDataContext = null;
            this.draggingConnectionDataContext = null;
        }
        /// <summary>
        /// This function does a hit test to determine which connector, if any, is under 'hitPoint'.
        /// </summary>
        private bool DetermineExecutionConnectorItemDraggedOver(Point hitPoint, out ExecutionConnectorItem executionConnectorItemDraggedOver, out object executionConnectorDataContextDraggedOver)
        {
            executionConnectorItemDraggedOver = null;
            executionConnectorDataContextDraggedOver = null;

            //
            // Run a hit test 
            //
            HitTestResult result = null;
            VisualTreeHelper.HitTest(nodeItemsControl, null,
                //
                // Result callback delegate.
                // This method is called when we have a result.
                //
                delegate (HitTestResult hitTestResult)
                {
                    result = hitTestResult;

                    return HitTestResultBehavior.Stop;
                },
                new PointHitTestParameters(hitPoint));

            if (result == null || result.VisualHit == null)
            {
                // Hit test failed.
                return false;
            }

            //
            // Actually want a reference to a 'ConnectorItem'.  
            // The hit test may have hit a UI element that is below 'ConnectorItem' so
            // search up the tree.
            //
            var hitItem = result.VisualHit as FrameworkElement;
            if (hitItem == null)
            {
                return false;
            }
            var executionConnectorItem = WpfUtils.FindVisualParentWithType<ExecutionConnectorItem>(hitItem);
            if (executionConnectorItem == null)
            {
                return false;
            }

            var networkView = executionConnectorItem.ParentNetworkView;
            if (networkView != this)
            {
                //
                // Ensure that dragging over a connector in another NetworkView doesn't
                // return a positive result.
                //
                return false;
            }

            object executionConnectorDataContext = executionConnectorItem;
            if (executionConnectorItem.DataContext != null)
            {
                //
                // If there is a data-context then grab it.
                // When we are using a view-model then it is the view-model
                // object we are interested in.
                //
                executionConnectorDataContext = executionConnectorItem.DataContext;
            }

            executionConnectorItemDraggedOver = executionConnectorItem;
            executionConnectorDataContextDraggedOver = executionConnectorDataContext;

            return true;
        }