VisualTreeHelper.GetTransform(Visual) Metoda

Definice

Transform Vrátí hodnotu pro Visualhodnotu .

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

Parametry

reference
Visual

Jejíž Visual hodnota transformace je vrácena.

Návraty

Transform

Hodnota transformace objektu Visualnebo null pokud reference nemá definovanou transformaci.

Příklady

Následující příklad kódu ukazuje, jak použít metodu GetTransform k načtení transformace pro zadaný vizuální objekt.

// 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

Kód by měl testovat null před použitím vrácené hodnoty. K vrácení posunu vrácené transformace použijte metodu Transform . Hodnota posunu je relativní k nadřazenosti objektu Visual.

Poznámky

Alternativně můžete použít metodu TransformToAncestor k vrácení transformační hodnoty pro nadřazeného Visualprvku . Tato metoda vždy vrátí platnou transformaci. Následující příklad kódu ukazuje, jak používat TransformToAncestor metodu.

// 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))

Platí pro