In the layout of Silverlight, controls are usually relatively placed, such as GRID/border/ListBox. In this case, the absolute position (location) of the Child control is obtained. What should I do? There are many application scenarios, such as clicking a button, opening a pop-up window for an animation, closing the window, and narrowing down the animation to the button position. In this way, we need to obtain the absolute position of the button. You can use the generaltransform. transform method to obtain it. Of course, you must first use uielement. transformtovisual to obtain the position relative to the ancestor.CodeAs follows:
1:Generaltransform GT = youruielment/* Control */. Transformtovisual (application. Current. rootvisualAsUielement );
2:Point offset = gt. Transform (NewPoint (0, 0 ));
3: DoubleControltop = offset. Y;
4: DoubleControlleft = offset. X;
Note: If you replace application. Current. rootvisual with other elements, you can obtain the relative location of the element relative to other elements ).
By the way, the premise is that you need to find the element first. You can use the findname method or traverse the Silverlight object tree. If you use a template, you can also use gettemplatechild. For more information, see the Silverlight Object Tree msdn.