如何在 WP7 中更新对象边距?
我正在开发 WP7 的应用程序。
在这个应用程序中有一些图片。当用户单击图像时,其他图像的坐标会发生变化。为此,我在任何图像上使用此代码:
picture.Margin = new Thickness(268, 90, 120, 225);
问题是,当我更改坐标时,图像之前所在的区域仍然可单击,即使它是空的并且图像位于不同的位置! (该事件适用于图像以及图像之前的位置,但我希望它仅适用于新位置)
我该怎么做?
I'm developing an application for WP7.
In this application there are some pictures. When an user clicks on an image, the coords of the other images change. To do this, I use this code on any image:
picture.Margin = new Thickness(268, 90, 120, 225);
The problem is that when I change the coords, the area where an image was before is still clickable, even if it's empty and the image is on a different place! (the event works on the image and also where the image was before, but I want It to only work on the new position)
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先尝试
InvalidateArange()
和InvalidateMeasure()
。恐怕可点击区域不仅在新旧位置 - 它存在边距不正确的问题,所以请再检查一次。
另外,如何处理图片上的点击事件(使用
GestureSercive
,将其放置在Button
内还是只是OnMouseLeftButtonUp
?)以及最后一个 - 布局有了这样的边距
268, 90, 120, 225
这不是一个好的做法。尝试了解元素之间的相互关系,并更好地设计布局。Try
InvalidateArange()
andInvalidateMeasure()
for the first.I'm afraid that clickable area not only in old and new position - it's problem with incorrect margins, so check it one more time, please.
Also, how you handle click event on your picture (with
GestureSercive
, you placed it insideButton
or justOnMouseLeftButtonUp
?)And the last - layout with such margins
268, 90, 120, 225
it's not a good practice. Try to understand how your elements relate to each other and design your layout better.