简体   繁体   中英

How to get a control's location in WP7 C#

Can anyone please inform me how I can get the location of a control? Apparently controlName.Margin.Top doesn't work for me. When I put a break-point, I get 0.0 for the Left value when obviously it's not, the control is half way in the screen.

It's something like

Point position = child.TransformToVisual(ancestor).Transform(new Point(0, 0));

where ancestor is the LayoutRoot or the Page and child is the Control in question.

EDIT: I just read your comment "I want to know what the position of the Control is on my Canvas". ancestor can of course be the direct parent as well.

However in this very case (where the direct parent is a Canvas) the following might be better: var top = myCanvas.GetTop(child);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM