語言

VisualTreeHelper.GetTransform(Visual) 方法

定義

回傳 Transform 的值。Visual

public:
 static System::Windows::Media::Transform ^ GetTransform(System::Windows::Media::Visual ^ reference);
public static System.Windows.Media.Transform GetTransform(System.Windows.Media.Visual reference);
static member GetTransform : System.Windows.Media.Visual -> System.Windows.Media.Transform
Public Shared Function GetTransform (reference As Visual) As Transform

參數

reference
Visual

Visual返回 的轉換值。

傳回

若 未定義轉換,則 的轉換值Visualnullreference。

範例

以下程式碼範例展示了如何使用該 GetTransform 方法取得指定視覺物件的轉換。

// Return the transform for the specified visual object.
Transform transform = VisualTreeHelper.GetTransform(myDrawing);

// If there is no transform defined for the object, the return value is null.
if (transform != null)
{
    // Return the offset of the returned transform. The offset is relative to the parent of the visual object.
    Point pt = transform.Transform(new Point(0, 0));
}
' Return the transform for the specified visual object.
Dim transform As Transform = VisualTreeHelper.GetTransform(myDrawing)

' If there is no transform defined for the object, the return value is null.
If transform IsNot Nothing Then
    ' Return the offset of the returned transform. The offset is relative to the parent of the visual object.
    Dim pt As Point = transform.Transform(New Point(0, 0))
End If

你的程式碼應該先測試 , null 再使用回傳的值。 要回傳回來的轉換偏移量,請使用以下 Transform 方法。 偏移值相對於 的父 Visual節點。

備註

或者,你也可以使用該 TransformToAncestor 方法回傳 的前祖 Visual變換值。 此方法總是回傳有效的轉換。 以下程式碼範例說明如何使用 TransformToAncestor 方法。

// Return the general transform for the specified visual object.
GeneralTransform generalTransform1 = myTextBlock.TransformToAncestor((Visual)myTextBlock.Parent);

// Retrieve the point value relative to the parent.
Point currentPoint = generalTransform1.Transform(new Point(0, 0));
' Return the general transform for the specified visual object.
Dim generalTransform1 As GeneralTransform = myTextBlock.TransformToAncestor(CType(myTextBlock.Parent, Visual))

' Retrieve the point value relative to the parent.
Dim currentPoint As Point = generalTransform1.Transform(New Point(0, 0))

適用於