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

            this.X = transformOffset.X;
            this.Y = transformOffset.Y;
        }
 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);
     }
 }
        internal void HandleDrag(Point newPositionInElementCoordinates)
        {
            double           x         = newPositionInElementCoordinates.X - this.relativePosition.X;
            double           y         = newPositionInElementCoordinates.Y - this.relativePosition.Y;
            GeneralTransform transform = base.AssociatedObject.TransformToVisual(this.RootElement);
            Point            point     = MouseDragElementBehavior.TransformAsVector(transform, x, y);

            this.settingPosition = true;
            this.ApplyTranslation(point.X, point.Y);
            this.UpdatePosition();
            this.settingPosition = false;
        }
 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);
     }
 }
        internal static Transform CloneTransform(Transform transform)
        {
            if (transform == null)
            {
                return(null);
            }
            transform.GetType();
            ScaleTransform scaleTransform;

            if ((scaleTransform = (transform as ScaleTransform)) != null)
            {
                return(new ScaleTransform
                {
                    CenterX = scaleTransform.CenterX,
                    CenterY = scaleTransform.CenterY,
                    ScaleX = scaleTransform.ScaleX,
                    ScaleY = scaleTransform.ScaleY
                });
            }
            RotateTransform rotateTransform;

            if ((rotateTransform = (transform as RotateTransform)) != null)
            {
                return(new RotateTransform
                {
                    Angle = rotateTransform.Angle,
                    CenterX = rotateTransform.CenterX,
                    CenterY = rotateTransform.CenterY
                });
            }
            SkewTransform skewTransform;

            if ((skewTransform = (transform as SkewTransform)) != null)
            {
                return(new SkewTransform
                {
                    AngleX = skewTransform.AngleX,
                    AngleY = skewTransform.AngleY,
                    CenterX = skewTransform.CenterX,
                    CenterY = skewTransform.CenterY
                });
            }
            TranslateTransform translateTransform;

            if ((translateTransform = (transform as TranslateTransform)) != null)
            {
                return(new TranslateTransform
                {
                    X = translateTransform.X,
                    Y = translateTransform.Y
                });
            }
            MatrixTransform matrixTransform;

            if ((matrixTransform = (transform as MatrixTransform)) != null)
            {
                return(new MatrixTransform
                {
                    Matrix = matrixTransform.Matrix
                });
            }
            TransformGroup transformGroup;

            if ((transformGroup = (transform as TransformGroup)) != null)
            {
                TransformGroup transformGroup2 = new TransformGroup();
                foreach (Transform current in transformGroup.Children)
                {
                    transformGroup2.Children.Add(MouseDragElementBehavior.CloneTransform(current));
                }
                return(transformGroup2);
            }
            return(null);
        }
        private static void OnConstrainToParentBoundsChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            MouseDragElementBehavior mouseDragElementBehavior = (MouseDragElementBehavior)sender;

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

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