Example #1
0
        /// <summary>
        /// Event raised when the user starts to drag a node.
        /// </summary>
        private void NodeItem_DragStarted(object source, NodeDragStartedEventArgs e)
        {
            e.Handled = true;

            IsDragging        = true;
            IsNotDragging     = false;
            IsDraggingNode    = true;
            IsNotDraggingNode = false;

            var eventArgs = new NodeDragStartedEventArgs(NodeDragStartedEvent, this, SelectedNodes);

            RaiseEvent(eventArgs);

            e.Cancel = eventArgs.Cancel;
        }
Example #2
0
        /// <summary>
        /// Called when the mouse cursor is moved.
        /// </summary>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (_isDragging)
            {
                //
                // Raise the event to notify that dragging is in progress.
                //

                var curMousePoint = e.GetPosition(ParentNetworkView);

                object item = this;
                if (DataContext != null)
                {
                    item = DataContext;
                }

                var offset = curMousePoint - _lastMousePoint;
                if (offset.Length <= Epsilon)
                {
                    return;
                }

                _lastMousePoint = curMousePoint;

                RaiseEvent(new NodeDraggingEventArgs(NodeDraggingEvent, this, new[] { item }, offset.X, offset.Y));
            }
            else if (_isLeftMouseDown && ParentNetworkView.EnableNodeDragging)
            {
                //
                // The user is left-dragging the node,
                // but don't initiate the drag operation until
                // the mouse cursor has moved more than the threshold distance.
                //
                var curMousePoint = e.GetPosition(ParentNetworkView);
                var dragDelta     = curMousePoint - _lastMousePoint;
                var dragDistance  = Math.Abs(dragDelta.Length);
                if (dragDistance > DragThreshold)
                {
                    //
                    // When the mouse has been dragged more than the threshold value commence dragging the node.
                    //

                    //
                    // Raise an event to notify that that dragging has commenced.
                    //
                    var eventArgs = new NodeDragStartedEventArgs(NodeDragStartedEvent, this, new[] { this });
                    RaiseEvent(eventArgs);

                    if (eventArgs.Cancel)
                    {
                        //
                        // Handler of the event disallowed dragging of the node.
                        //
                        _isLeftMouseDown           = false;
                        _isLeftMouseAndControlDown = false;
                        return;
                    }

                    _isDragging = true;
                    CaptureMouse();
                    e.Handled = true;
                }
            }
        }