Visual.TransformToDescendant(Visual) Visual.TransformToDescendant(Visual) Visual.TransformToDescendant(Visual) Visual.TransformToDescendant(Visual) Method


傳回轉換,這個轉換可用來將 Visual 的座標轉換為指定的視覺物件子系。Returns a transform that can be used to transform coordinates from the Visual to the specified visual object descendant.

 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


Visual Visual Visual Visual

座標會轉換為 VisualThe Visual to which the coordinates are transformed.



視覺不是 descendant 視覺物件的祖系。The visual is not an ancestor of the descendant visual.

這些視覺物件都不會產生關聯。The visual objects are not related.


下列標記範例顯示TextBlock包含StackPanel在物件中的。The following markup example shows a TextBlock that is contained within a StackPanel object.

<StackPanel Name="myStackPanel" Margin="8">
  <TextBlock Name="myTextBlock" Margin="4" Text="Hello, world" />

下列程式碼範例示範如何使用TransformToDescendant方法來抓取StackPanel相對於其子TextBlock系的位移。The following code example shows how to use the TransformToDescendant method to retrieve the offset of the StackPanel relative to its child TextBlock. 位移值會包含在傳回GeneralTransform的值內。The offset values are contained within the returned GeneralTransform value.

// 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值。The offset takes into account the Margin values for all objects. 在此情況下X , 是-4, Y而是-4。In this case, X is -4, and Y is -4. 位移值是負值, 因為父物件相對於其子物件有負面的位移。The offset values are negative values because the parent object is negatively offset relative to its child object.