如何找到'SomeRectangle'的位置?
这个矩形是我需要从'somepicture'裁剪的位置和大小,实际上是主网格背景中出现的图片。
<Rectangle x:Name="SomeRectangle" Height="50" Width="50" Stroke="Red" HorizontalAlignment="Center" VerticalAlignment="Center" MinWidth="5" MinHeight="5" />
答案 0 :(得分:1)
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;