Silverlight, WPF. How to determine is one control located over other?
What is the best solution to check is one control located over other.
For example, I have开发者_运维问答 two TextBoxes and when one TextBox is over the other I need to hide one of them.
AND i need to determine is this cotnrols overlaped before i will add them to visul tree!
I assume you mean you want to find out if they overlap in the Z-dimension?
Untested:
// requires System.Windows.Controls.Toolkit.dll
using System.Windows.Controls.Primitives;
// ...
Rect? rect1 = myControl1.GetBoundsRelativeTo(someParentContainer);
Rect? rect2 = myControl2.GetBoundsRelativeTo(someParentContainer);
bool areIntersecting = rect1 != null && rect2 != null
&& rect1.Value.Intersect(rect2.Value) != Rect.Empty;
If you're after a tool rather than a programmatic solution, snoop does this for WPF apps. It shows you a hierarchical view of the composition of controls in your app at runtime.
Never used it, but Silverlight Spy seems to be a Silverlight equivalent.
精彩评论