1, gets the position of the element relative to the parent control
Using the Vector Visualtreehelper.getoffset (visual visual) method, it returns the offset of visual in its parent control, and then you can then convert the vector object that returns the value to a point object.
2, gets the position of the element relative to the ancestor control or descendant control
Use the Generaltransform transformtoancetor (visual Ancetor) method of the element with Generaltransform transformtodescendent (visual descendent), whose return element is relative to the generaltransform mygeneraltransform of the ancestor or descendant, and then uses Point thepoint= mygeneraltransform.transform ( The Thepoint object that is obtained by New Point (0,0) is the value you are looking for.
3, get the relative position of any two elements
There are two ways of doing this:
If the element is visual, you can use the element's Generaltransform transformtovisual (visual visual) method, and then you can get thepoint from Generaltransform with the method 2nd above
If the element is UIElement, it is simpler to use the element's Translatepoint (Point pt, UIElement relativeto) to get the value of the PT points on the element relative to RelativeTo, only our incoming PT is (0 , 0) Then you can get the relative position of the point on the Element (0,0), that is, the relative position of the element
Original address: http://www.cnblogs.com/zhouyinhui/archive/2008/03/20/1115132.html
Get the relative position between controls in WPF