我有一个画布(ZoomableCanvas),它实现了缩放并有子项。我试图在放大时获取子项的相对位置,以便在其上显示扩展信息。
<Canvas x:Name="CanvasContainer" Width="1500" Height="780">
<ZoomableCanvas ApplyTransform="false" Loaded="ZoomableCanvas_Loaded" x:Name="ShareCanvas" Width="1500" Height="780" MinWidth="1500" MinHeight="780" Grid.Row="0" Grid.Column="0" />
</Canvas>
后面的代码:
Canvas main = touched.FindVisualParent<Canvas>(); //Finds "CanvasContainer"
Point relativePoint = touched.TransformToAncestor(main).Transform(new Point(0, 0));
double canvasTop = Canvas.GetTop(touched);
但是在这里 canvasTop != relativePoint.Y 在缩放之前?
我是不是用错了。它不是映射到父视觉并给出一个相对点吗?