views:

468

answers:

2

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?

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

Thanks. Eli

+1  A: 

The dimension (FrameworkElement.ActualWith 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.

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.

bitbonk
+3  A: 

You can use the Rect.IntersectsWith method

Thomas Levesque