VisualTreeHelper.GetTransform(Visual) Metodo

Definizione

Restituisce un valore Transform per l'oggetto 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

Parametri

reference
Visual

Oggetto Visual di cui viene restituito il valore di trasformazione.

Restituisce

Valore di trasformazione dell'oggetto Visual oppure null se per reference non è stata definita alcuna trasformazione.

Esempio

Nell'esempio di codice seguente viene illustrato come usare il GetTransform metodo per recuperare la trasformazione per l'oggetto visivo specificato.

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

Il codice deve essere testato prima null di usare il valore restituito. Per restituire l'offset della trasformazione restituita, usare il Transform metodo . Il valore di offset è relativo all'elemento padre di Visual.

Commenti

In alternativa, è possibile usare il TransformToAncestor metodo per restituire un valore di trasformazione per il predecessore di un Visualoggetto . Questo metodo restituisce sempre una trasformazione valida. Nell'esempio di codice seguente viene illustrato come usare TransformToAncestor il metodo.

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

Si applica a