(0 votes)

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

0 comments   /   posted by Denislav Savkov on Aug 29, 2008

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!

Filed under: Controls and UI


Comments

Comments RSS RSS
No comments

Add Comment