[Silverlight entry series] Use transformtovisual and transform to obtain the absolute location of an element)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.