How can I get the position of a child element relative to a parent?

It can be done using TranslatePoint method of the control.

UIElement container = VisualTreeHelper.GetParent(control) as UIElement;
Point relativeLocation = control.TranslatePoint(new Point(0, 0), container);

new Point(0, 0) represents the top left point of the control and TranslatePoint will return the location of that point relative to the parent control (I assumed here the parent is a UIElement).
You can place instead of container any ancestor of the control.

Leave a Comment