VisualTreeHelper.GetTransform(Visual) Méthode

Définition

Renvoie une valeur Transform pour le 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

Paramètres

reference
Visual

Le Visual dont la valeur de transformation est renvoyée.

Retours

La valeur de transformation du Visual, ou null si reference n'a pas de valeur de transformation définie.

Exemples

L’exemple de code suivant montre comment utiliser la GetTransform méthode pour récupérer la transformation de l’objet visuel spécifié.

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

Votre code doit être testé null avant d’utiliser la valeur retournée. Pour retourner le décalage de la transformation retournée, utilisez la Transform méthode . La valeur de décalage est relative au parent de .Visual

Remarques

Vous pouvez également utiliser la TransformToAncestor méthode pour retourner une valeur de transformation pour l’ancêtre d’un Visual. Cette méthode retourne toujours une transformation valide. L’exemple de code suivant montre comment utiliser la TransformToAncestor méthode.

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

S’applique à