VisualTreeHelper.GetTransform(Visual) Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
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
Parametrar
Returer
Transformeringsvärdet för Visual, eller null om reference inte har en transformering definierad.
Exempel
I följande kodexempel visas hur du använder GetTransform metoden för att hämta transformering för det angivna visuella objektet.
// 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
Koden bör testas innan null du använder det returnerade värdet. Använd metoden för att returnera förskjutningen för den returnerade transformeringen Transform . Förskjutningsvärdet är relativt det överordnade värdet för Visual.
Kommentarer
Du kan också använda TransformToAncestor metoden för att returnera ett transformeringsvärde för överordnade för en Visual. Den här metoden returnerar alltid en giltig transformering. I följande kodexempel visas hur du använder TransformToAncestor metoden.
// 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))