In some scenarios we need to find out what are the objects located at a specific point or in a certain area. In this case we get access to the System.Windows.UIElelement objects using the UIElement.HitTest method. It can test a Rect area or a Point. The return value is a collection of the children in this area arranged from the top element to the bottom.
C#
Rect areaInAbsoluteCoordinates = new Rect( areaLeftCoordinate, areaTopCoordinate, areaWidth, areaHeight );
IEnumerable<UIElement> childrenInArea = panel.HitTest(areaInAbsoluteCoordinates );
Note! In Silverlight the coordinates for hit testing are the absolute coordinates of the application. In case you want to hit test with coordinates relative to an UIElement see our tip.
Note! To get all the elements in an area you must use Application.Current.VisualRoot.HitTest.
That’s it!