private void ApplyTranslation()

in src/Microsoft.Xaml.Behaviors/Layout/MouseDragElementBehavior.cs [233:283]


        private void ApplyTranslation(double x, double y)
        {
            if (this.ParentElement != null)
            {
                GeneralTransform rootToParent = this.RootElement.TransformToVisual(this.ParentElement);
                Point transformedPoint = MouseDragElementBehavior.TransformAsVector(rootToParent, x, y);
                x = transformedPoint.X;
                y = transformedPoint.Y;

                if (this.ConstrainToParentBounds)
                {
                    FrameworkElement parentElement = this.ParentElement;
                    Rect parentBounds = new Rect(0, 0, parentElement.ActualWidth, parentElement.ActualHeight);

                    GeneralTransform objectToParent = this.AssociatedObject.TransformToVisual(parentElement);
                    Rect objectBoundingBox = this.ElementBounds;
                    objectBoundingBox = objectToParent.TransformBounds(objectBoundingBox);

                    Rect endPosition = objectBoundingBox;
                    endPosition.X += x;
                    endPosition.Y += y;

                    if (!MouseDragElementBehavior.RectContainsRect(parentBounds, endPosition))
                    {
                        if (endPosition.X < parentBounds.Left)
                        {
                            double diff = endPosition.X - parentBounds.Left;
                            x -= diff;
                        }
                        else if (endPosition.Right > parentBounds.Right)
                        {
                            double diff = endPosition.Right - parentBounds.Right;
                            x -= diff;
                        }

                        if (endPosition.Y < parentBounds.Top)
                        {
                            double diff = endPosition.Y - parentBounds.Top;
                            y -= diff;
                        }
                        else if (endPosition.Bottom > parentBounds.Bottom)
                        {
                            double diff = endPosition.Bottom - parentBounds.Bottom;
                            y -= diff;
                        }
                    }
                }

                this.ApplyTranslationTransform(x, y);
            }
        }