VisualTreeHelper.GetTransform(Visual) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
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
Parâmetros
Devoluções
O valor da transformada do Visual, ou null se reference não tiver uma transformada definida.
Exemplos
O exemplo de código seguinte mostra como usar o GetTransform método para recuperar a transformação para o objeto visual especificado.
// 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
O teu código deve testar antes null de usar o valor devolvido. Para devolver o deslocamento da transformada retornada, use o Transform método. O valor de deslocamento é relativo ao pai do Visual.
Observações
Alternativamente, pode usar o TransformToAncestor método para devolver um valor de transformação para o ancestral de um Visual. Este método retorna sempre uma transformação válida. O seguinte exemplo de código mostra como usar TransformToAncestor o método.
// 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))