Skip Navigation LinksHome / Tips / View Tip

Tip: How to find out the UI elements located in an area?

+ Add to SilverlightShow Favorites
0 comments   /   posted by Denislav Savkov on Aug 29, 2008
(0 votes)
Categories: Controls and UI

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!

Share


Comments

Comments RSS RSS
No comments

Add Comment

 
 

   
  
  
   
Please add 7 and 3 and type the answer here:

Join the free SilverlightShow webcast 'Running Silverlight Outside the Browser and with Elevated Trust'. Sept 7th, 8 am - 9 am PDT.
In this live session Chris Anderson will cover configuring and debugging OOB mode, toast notifications, elevated trust, direct file access and much more.
Learn more | Register | See more webinars (hide this)