Example #1
0
        /// <summary>
        /// Method is executed if a shape is dragged across the canvas.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="delta"></param>
        void ICanvasViewMouseHandler.OnShapeDragUpdate(Point position, Vector delta)
        {
            if (this.mPart_ItemsControl == null)
            {
                return;
            }

            foreach (ShapeViewModelBase shape in CanvasViewModel.SelectedItem.Shapes)
            {
                FrameworkElement control = this.ControlFromElement(shape);

                if ((bool)control.GetValue(CanvasView.CustomDragProperty))
                {
                    continue;
                }

                // Get current position of shape
                Point origin = shape.Position;

                // Move shape by this delta in X and Y
                Point p = origin + delta;

                // Check whether the new position is legal and optimize based on the canvas view size
                if (p.X < 0)
                {
                    p.X = 0;
                }
                else
                {
                    if (p.X + control.ActualWidth > this.mPart_ItemsControl.ActualWidth)
                    {
                        p.X = this.mPart_ItemsControl.ActualWidth - control.ActualWidth;
                    }
                }

                if (p.Y < 0)
                {
                    p.Y = 0;
                }
                else
                {
                    if (p.Y + control.ActualHeight > this.mPart_ItemsControl.ActualHeight)
                    {
                        p.Y = this.mPart_ItemsControl.ActualHeight - control.ActualHeight;
                    }
                }

                // Set shape to new position
                shape.Position = p;

                // Invoke snap event if possible to let lines adjust correctly
                if (control is ISnapTarget)
                {
                    ISnapTarget ist = control as ISnapTarget;
                    ist.NotifySnapTargetUpdate(new SnapTargetUpdateEventArgs(p - origin));
                }
            }
        }
Example #2
0
 /// <summary>
 /// Occurs when the SnapTargetUpdate event occurs
 /// in the ISnapTarget dependency property.
 /// </summary>
 /// <param name="source"></param>
 /// <param name="e"></param>
 private void snapTargetUpdate(ISnapTarget source, SnapTargetUpdateEventArgs e)
 {
     if (e.IsMoveUpdate == MoveUpdate.MoveDelta)
     {
         this.MoveTo(new Point(this.Left, this.Top) + e.MoveDelta);
     }
     else
     {
         this.CoerceLater();
     }
 }
Example #3
0
 private void snapTargetUpdate(ISnapTarget source, SnapTargetUpdateEventArgs e)
 {
     if (e.isMoveUpdate)
     {
         MoveTo(new Point(Left, Top) + e.moveDelta);
     }
     else
     {
         CoerceLater();
     }
 }
Example #4
0
        void ICanvasViewMouseHandler.OnShapeDragUpdate(Point position, Vector delta)
        {
            foreach (XElement shape in _CanvasViewModel.prop_SelectedShapes)
            {
                FrameworkElement control = ControlFromElement(shape);

                if ((bool)control.GetValue(CanvasView.CustomDragProperty))
                {
                    continue;
                }

                Point origin = shape.GetPositionAttributes();

                Point p = origin + delta;

                if (p.X < 0)
                {
                    p.X = 0;
                }
                else if (p.X + control.ActualWidth > _itemsControl.ActualWidth)
                {
                    p.X = _itemsControl.ActualWidth - control.ActualWidth;
                }

                if (p.Y < 0)
                {
                    p.Y = 0;
                }
                else if (p.Y + control.ActualHeight > _itemsControl.ActualHeight)
                {
                    p.Y = _itemsControl.ActualHeight - control.ActualHeight;
                }

                shape.SetPositionAttributes(p);

                ISnapTarget ist = control as ISnapTarget;
                if (ist != null)
                {
                    ist.NotifySnapTargetUpdate(new SnapTargetUpdateEventArgs(p - origin));
                }
            }
        }
 private void snapTargetUpdate(ISnapTarget source, SnapTargetUpdateEventArgs e)
 {
     NotifySnapTargetUpdate(e);
 }