我正在学习如何在windows phone 7中收缩、拖动和旋转图像。但我注意到,图像可以拖动、缩小屏幕。
有没有办法限制图像的宽度/高度?
发布于 2012-05-01 18:15:11
我认为你需要自己实现约束。基本上,您总是有一个包含图像的容器元素,我假设这个容器设置了宽度/高度。
容器和图像在空间上都有4个点(左上、右上、左下、右下)。对于约束,您只需要检查图像的这些点都没有超过容器点。
要计算左上点,请使用:
var transform = image.TransformToVisual(container);         
Point topLeftPoint = transform.Transform(new Point(0, 0));要计算右上点,只需将Image.Width添加到topLeftPoint.X。要计算左下点,请将Image.Height添加到topLeftPoint.Y。要计算右下点,请将Image.Height和Image.Width分别添加到topLeftPoint.Y和topLeftPoint.X。
然后您只需要检查ContainerTopLeftPoint.X >= ImageTopLeftPoint.X和ContainerTopLeftPoint.Y >= ImageTopLeftPoint.Y...对每个点进行类似的检查(但请记住,对于最低点,它应该是<=而不是>= )。
纯数学:)
https://stackoverflow.com/questions/10361799
复制相似问题