Recommended

Skip Navigation LinksHome / Tips / View Tip

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

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

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!

Share


Comments

Comments RSS RSS
  • 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.

Add Comment

 
 

   
  
  
   
Please add 7 and 6 and type the answer here:

Help us make SilverlightShow even better. Whether you'd like to suggest a change in the structure, content organization, section layout or any other aspect of SilverlightShow appearance - we'd love to hear from you! Need material (article, tutorial, or other) on a specific topic? Let us know and SilverlightShow content authors will work to have that prepared for you. (hide this)