返回一个转换,该转换可用于将坐标从Visual转换为指定的视觉对象。
public System.Windows.Media.GeneralTransform TransformToVisual (System.Windows.Media.Visual visual);
一个例子
以下标记示例显示了StackPanel对象中包含的TextBlock。
XAML复制
下面的代码示例演示如何使用TransformToVisual方法获取其子TextBlock的StackPanel的偏移量。偏移值包含在返回的GeneralTransform值中。
C#复制
// 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));
偏移量考虑所有对象的边距值。在这种情况下,X为-4,Y为-4。偏移值为负,因为父对象相对于其子对象具有负偏移。
注解使用TransformToAncestor方法和使用TransformToDescendant方法,还可以返回可视对象的转换。