Exemplo n.º 1
0
        private void UpdatePosition()
        {
            GeneralTransform transform       = base.AssociatedObject.TransformToVisual(this.RootElement);
            Point            transformOffset = MouseDragElementBehavior.GetTransformOffset(transform);

            this.X = transformOffset.X;
            this.Y = transformOffset.Y;
        }
Exemplo n.º 2
0
 private void UpdatePosition(Point point)
 {
     if (!this.settingPosition && base.AssociatedObject != null)
     {
         GeneralTransform transform       = base.AssociatedObject.TransformToVisual(this.RootElement);
         Point            transformOffset = MouseDragElementBehavior.GetTransformOffset(transform);
         double           x = double.IsNaN(point.X) ? 0.0 : (point.X - transformOffset.X);
         double           y = double.IsNaN(point.Y) ? 0.0 : (point.Y - transformOffset.Y);
         this.ApplyTranslation(x, y);
     }
 }
Exemplo n.º 3
0
 private void ApplyTranslation(double x, double y)
 {
     if (this.ParentElement != null)
     {
         GeneralTransform transform = this.RootElement.TransformToVisual(this.ParentElement);
         Point            point     = MouseDragElementBehavior.TransformAsVector(transform, x, y);
         x = point.X;
         y = point.Y;
         if (this.ConstrainToParentBounds)
         {
             FrameworkElement parentElement    = this.ParentElement;
             Rect             rect             = new Rect(0.0, 0.0, parentElement.ActualWidth, parentElement.ActualHeight);
             GeneralTransform generalTransform = base.AssociatedObject.TransformToVisual(parentElement);
             Rect             rect2            = this.ElementBounds;
             rect2 = generalTransform.TransformBounds(rect2);
             Rect rect3 = rect2;
             rect3.X += x;
             rect3.Y += y;
             if (!MouseDragElementBehavior.RectContainsRect(rect, rect3))
             {
                 if (rect3.X < rect.Left)
                 {
                     double num = rect3.X - rect.Left;
                     x -= num;
                 }
                 else
                 {
                     if (rect3.Right > rect.Right)
                     {
                         double num2 = rect3.Right - rect.Right;
                         x -= num2;
                     }
                 }
                 if (rect3.Y < rect.Top)
                 {
                     double num3 = rect3.Y - rect.Top;
                     y -= num3;
                 }
                 else
                 {
                     if (rect3.Bottom > rect.Bottom)
                     {
                         double num4 = rect3.Bottom - rect.Bottom;
                         y -= num4;
                     }
                 }
             }
         }
         this.ApplyTranslationTransform(x, y);
     }
 }
Exemplo n.º 4
0
        private static void OnConstrainToParentBoundsChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            MouseDragElementBehavior mouseDragElementBehavior = (MouseDragElementBehavior)sender;

            mouseDragElementBehavior.UpdatePosition(new Point(mouseDragElementBehavior.X, mouseDragElementBehavior.Y));
        }
Exemplo n.º 5
0
        private static void OnYChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            MouseDragElementBehavior mouseDragElementBehavior = (MouseDragElementBehavior)sender;

            mouseDragElementBehavior.UpdatePosition(new Point(mouseDragElementBehavior.X, (double)args.NewValue));
        }