コード例 #1
0
        private void AssociatedObject_QueryContinueDrag(object sender, QueryContinueDragEventArgs e)
        {
            var element = GetSenderDiagram(sender) ?? sender as UIElement;

            if (element == null)
            {
                return;
            }

            DrawLineAdorner adorner = GetDraggingLineAdorner(element);
            Point           point   = WPFUtility.GetMousePosition(element);

            if (adorner != null)
            {
                adorner.Position = point;
            }
        }
コード例 #2
0
        private void AssociatedObject_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Released)
            {
                return;
            }

            //use the connection object base on ConnectionDiagramBase
            var element = GetSenderDiagram(sender) ?? sender as UIElement;

            if (element == null)
            {
                return;
            }

            Point point = e.GetPosition(element as UIElement);


            Point startPoint = (element as ConnectionDiagramBase)?.CenterPosition ?? new Point(0, 0);

            //change the draw line center position
            int centerradius = (element as ConnectionDiagramBase)?.CenterPositionRadius ?? 0;

            if (!WPFUtility.IsCenterDragging(startPoint, point, centerradius))
            {
                return;
            }

            if (!WPFUtility.IsDragging(startPoint, point))
            {
                return;
            }

            DrawLineAdorner adorner = new DrawLineAdorner(element, 0.7, point);

            SetDraggingLineAdorner(element, adorner);

            DataObject data = new DataObject();

            //set the adorner for drop action and create the clone element.
            data.SetData(typeof(UIElement), element);
            data.SetData(typeof(DrawLineAdorner), adorner);

            ICommand dragcommand = GetDragLineCommand(element);

            //cann't drag without command
            if (dragcommand != null)
            {
                object parameter = GetDragLineCommandParameter(element); //?? this.AssociatedObject.DataContext;

                if (parameter != null)
                {
                    data.SetData(DataFormats.Serializable, parameter);
                }

                if (dragcommand.CanExecute(parameter))
                {
                    dragcommand.Execute(parameter);
                    DragDrop.DoDragDrop(element, data, DragDropEffects.Copy | DragDropEffects.Move);
                }
            }

            adorner.Remove();

            SetDraggingLineAdorner(element, null);
        }
コード例 #3
0
 /// <summary>
 /// Sets the value of the DraggingLineAdorner attached property
 /// for a given dependency object.
 /// </summary>
 /// <param name="obj">The object to which the property value
 /// is written.</param>
 /// <param name="value">Sets the DraggingLineAdorner value of the specified object.</param>
 public static void SetDraggingLineAdorner(DependencyObject obj, DrawLineAdorner value)
 {
     obj.SetValue(DraggingLineAdornerProperty, value);
 }