Visual.TransformToDescendant(Visual) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回一个转换,该转换可用于将坐标从 Visual 指定的视觉对象子代转换到指定视觉对象后代。
public:
System::Windows::Media::GeneralTransform ^ TransformToDescendant(System::Windows::Media::Visual ^ descendant);
public System.Windows.Media.GeneralTransform TransformToDescendant(System.Windows.Media.Visual descendant);
member this.TransformToDescendant : System.Windows.Media.Visual -> System.Windows.Media.GeneralTransform
Public Function TransformToDescendant (descendant As Visual) As GeneralTransform
参数
返回
一个 GeneralTransform 类型的值。
例外
descendant 是 null。
视觉对象不是视觉对象的 descendant 上级。
视觉对象不相关。
示例
以下标记示例演示 TextBlock 对象中包含的对象 StackPanel 。
<StackPanel Name="myStackPanel" Margin="8">
<TextBlock Name="myTextBlock" Margin="4" Text="Hello, world" />
</StackPanel>
下面的代码示例演示如何使用TransformToDescendant该方法检索相对于其子StackPanel元素的TextBlock偏移量。 偏移值包含在返回 GeneralTransform 的值内。
// Return the general transform for the specified visual object.
GeneralTransform generalTransform1 = myStackPanel.TransformToDescendant(myTextBlock);
// Retrieve the point value relative to the child.
Point currentPoint = generalTransform1.Transform(new Point(0, 0));
' Return the general transform for the specified visual object.
Dim generalTransform1 As GeneralTransform = myStackPanel.TransformToDescendant(myTextBlock)
' Retrieve the point value relative to the child.
Dim currentPoint As Point = generalTransform1.Transform(New Point(0, 0))
偏移量将考虑 Margin 所有对象的值。 在本例中, X 为 -4,为 Y -4。 偏移值是负值,因为父对象相对于其子对象是负偏移量。