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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…