2011-05-23 68 views
1

我如何找到'SomeRectangle'的位置?如何找到一些上層控制的控制位置?

這個矩形是我需要從'somepicture'裁剪的位置和大小,它實際上是出現在主網格背景中的圖片。

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

回答

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; 

Source: Silverlight Forum