开发者

How to find the location of control on some upper level control?

开发者 https://www.devze.com 2023-03-07 23:42 出处:网络
How can i find the location of the \'SomeRectangle\' ? This Rectangle is the location and the size that i need to crop from t开发者_开发知识库he \'somepicture\' that is actually the picture that app

How can i find the location of the 'SomeRectangle' ?

This Rectangle is the location and the size that i need to crop from t开发者_开发知识库he 'somepicture' that is actually the picture that appear in the background of the main grid.

    <Rectangle x:Name="SomeRectangle" Height="50" Width="50" Stroke="Red" HorizontalAlignment="Center" VerticalAlignment="Center" MinWidth="5" MinHeight="5" />


GeneralTransform gt = 
    SomeRectangle.TransformToVisual(Application.Current.RootVisual as UIElement);
Point offset = gt.Transform(new Point(0, 0));
double controlTop = offset.Y;
double controlLeft = offset.X;

Source: Silverlight Forum

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号