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

Tip: How to get the relative coordinates of an element?

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

You can get the coordinates of a System.Windows.UIElement relative to any other UIElement. Probably the most common scenario is to get the coordinates of a child element so this is our example.

C#

GeneralTransform generalTransform = childElement.TransformToVisual( parentElement );
Point childToParentCoordinates = generalTransform.Transform( new Point( 0, 0 ) );

Note! If the child is in left of the parent element or above it, the coordinates will be negative.

That's it!


Subscribe

Comments

  • -_-

    RE: Tip: How to get the relative coordinates of an element?


    posted by Poornima on May 07, 2009 09:00
    Thank you, that worked like a champ :)
  • -_-

    RE: Tip: How to get the relative coordinates of an element?


    posted by subrat on Jul 24, 2009 15:42
    Thanks a ton.It solved my problem m pondering since 2 days.
  • -_-

    RE: Tip: How to get the relative coordinates of an element?


    posted by Bryan on Jul 20, 2010 22:21
    Where in the world did you find this snippet? Is this actually documented by Microsoft somewhere? Thanks a million. This was a huge help.
  • -_-

    RE: Tip: How to get the relative coordinates of an element?


    posted by Noah on Feb 17, 2011 20:16

    Many thanks, this was simple to implement and worked exactly as advertised!

    Your time is appreciated!

Add Comment

Login to comment:
  *      *       
Login with Facebook