简体   繁体   中英

How do you find the screen position of a control in silverlight on WP7?

How do you find the screen position of a control in silverlight on WP7?

Any suggestions are much appreciated.

If you know how it's positioned (eg in a Canvas ) there may be a more appropriate way to do things, but in general, you can use UIElement.TransformToVisual to convert between the control's and the global coordinate system:

var transform = myControl.TransformToVisual(Application.Current.RootVisual)
var offset = transform.Transform(new Point(0,0))

Be sure that the control has undergone layout before trying to do this, if you do it too early the error messages are generally unhelpful.

(MSDN suggests the method is present in WP7, I don't have the SDK installed to test)

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