0
canvas
內有幾個長方形。如何使用C#
中的矩形的Name
來獲取矩形的wrt畫布的座標?帆布元素的兒童座標
canvas
內有幾個長方形。如何使用C#
中的矩形的Name
來獲取矩形的wrt畫布的座標?帆布元素的兒童座標
您可以使用TransformToVisual來做到這一點。這裏有一個很好的例子:Visual.TransformToVisual MSDN
從頁面後人:
<StackPanel Name="myStackPanel" Margin="8">
<TextBlock Name="myTextBlock" Margin="4" Text="Hello, world" />
</StackPanel>
// Return the general transform for the specified visual object.
GeneralTransform generalTransform1 = myStackPanel.TransformToVisual(myTextBlock);
// Retrieve the point value relative to the child.
Point currentPoint = generalTransform1.Transform(new Point(0, 0));
感謝您的幫助 –