我有一个图像,我在缩放后将其平移,在水平平移时,图像被移动,左侧留有空白。我想限制图像何时达到左边界。顶部,右侧,底部平移也是如此。
private void Grid1_MouseMove(object sender, MouseEventArgs e)
{
if (!image1.IsMouseCaptured) return;
Point p = e.MouseDevice.GetPosition(image1);
var rect2 = new Rect(image1.RenderSize);
Bounds = image1.TransformToAncestor(grid1).TransformBounds(rect2);
matrix = zoomMatrixTransform.Matrix;
Vector v = start - e.GetPosition(grid1);
matrix.OffsetX = origin.X - v.X;
matrix.OffsetY = origin.Y - v.Y;
zoomMatrixTransform.Matrix = matrix;
image1.RenderTransformOrigin = new Point(0.5, 0.5);
image1.LayoutTransform = zoomMatrixTransform;
}
我已附加平移的图像,并且希望限制红色突出显示区域。还附上了预期的输出。