如何检查2个控件是否在WPF的画布上重叠? [英] How can i check if 2 controls overlap eachother on a canvas in WPF?

查看:1144
本文介绍了如何检查2个控件是否在WPF的画布上重叠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写一个设计器,使用户可以在屏幕上拖动控件。
在我拖动一个控件的时候,检测控件是否与另一个控件重叠的最好方法是什么?

I am writing a designer that enables the user to drag controls around the screen. What would be the best way of detecting if a control is overlapping another control while i am dragging the one control around?

我应该得到的尺寸FrameworkElement并继续检查其他元素的维度?

Should i just get the dimensions of the FrameworkElement and keep on checking the dimensions of the other elements?

谢谢。
Eli

Thanks. Eli

推荐答案

尺寸(FrameworkElement.ActualWidth FrameworkElement.ActualHeight)和位置(Canvas.Top,Canvas.Bottom ,Canvas.Left,Canvas.Right)的元素就足够了,如果他们总是矩形。在这种情况下,您可以轻松计算两个矩形是否重叠。如果你的元素可以是更复杂的形状,它会变得毛茸茸。我不知道我是否可以测试两个Visual实例在WPF的交集。

The dimension (FrameworkElement.ActualWidth FrameworkElement.ActualHeight) and postion (Canvas.Top, Canvas.Bottom,Canvas.Left, Canvas.Right) of your elements would suffice if they are always rectangular. In that case you can easily calculate if two rectangles overlap. If you elements can be of more complex shapes it gets hairy. I have no idea if I can test for intersection of two Visual instances in WPF.

也许我们可以使用 hittesting ?使用此方法,您至少可以测试某个几何与证书视觉。所以你必须定义几何或点列表,或多或少地紧密匹配你的第二个视觉的边界。

Maybe we can use hittesting? With this approach you could at least test if a certain point or geometry intersect with a certian visual. So you would have to define a geometry or a list of points that more or less closely match the bounds of your 2nd visual.

这篇关于如何检查2个控件是否在WPF的画布上重叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆