1

我正在关注这篇文章来学习如何在 windows phone 7 中捏合、拖动和旋转图像。但我注意到图像可以从屏幕上拖动、缩小。

有没有办法限制图像的宽度/高度?

4

1 回答 1

1

我认为您将需要自己实施约束。基本上你总是有一个包含图像的容器元素,我假设这个容器有一个宽度/高度集。

容器和图像都有 4 个空间点(左上、右上、左下、右下)。对于约束,您只需要检查图像的这些点都不会超过容器点。

要计算左上角点,请使用:

var transform = image.TransformToVisual(container);         
Point topLeftPoint = transform.Transform(new Point(0, 0));

要计算右上角点,只需将 Image.Width 添加到 topLeftPoint.X。要计算左下角点,请将 Image.Height 添加到 topLeftPoint.Y。要计算右下角点,请将 Image.Height 添加到 topLeftPoint.Y 并将 Image.Width 添加到 topLeftPoint.X。

然后您只需要检查 ContainerTopLeftPoint.X >= ImageTopLeftPoint.X 和 ContainerTopLeftPoint.Y >= ImageTopLeftPoint.Y... 对每个点进行类似检查(但请记住,对于底点,它应该是 <= 而不是 >= )。

纯数学:)

于 2012-05-01T10:15:11.367 回答