(X) Hide this
    • Login
    • Join
      • Say No Bots Generate New Image
        By clicking 'Register' you accept the terms of use .
        Login with Facebook

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

(0 votes)
Denislav Savkov
>
Denislav Savkov
Joined Feb 11, 2008
Articles:   14
Comments:   6
More Articles
0 comments   /   posted on Aug 29, 2008
Tags:   denislav-savkov
Categories:   General

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!


Subscribe

Comments

No comments

Add Comment

Login to comment:
  *      *       
Login with Facebook