Visual.TransformToVisual(Visual) Metoda
Definicja
public:
System::Windows::Media::GeneralTransform ^ TransformToVisual(System::Windows::Media::Visual ^ visual);
public System.Windows.Media.GeneralTransform TransformToVisual (System.Windows.Media.Visual visual);
member this.TransformToVisual : System.Windows.Media.Visual -> System.Windows.Media.GeneralTransform
Public Function TransformToVisual (visual As Visual) As GeneralTransform
Parametry
- visual
- Visual
, Visual Do którego współrzędne są przekształcane.The Visual to which the coordinates are transformed.
Zwraca
Wartość typu GeneralTransform .A value of type GeneralTransform.
Wyjątki
visual
to null
.visual
is null
.
Obiekty wizualne nie są powiązane.The visual objects are not related.
Przykłady
Poniższy przykład znaczników pokazuje TextBlock , który jest zawarty w StackPanel obiekcie.The following markup example shows a TextBlock that is contained within a StackPanel object.
<StackPanel Name="myStackPanel" Margin="8">
<TextBlock Name="myTextBlock" Margin="4" Text="Hello, world" />
</StackPanel>
Poniższy przykład kodu pokazuje, jak używać TransformToVisual metody do pobierania przesunięcia StackPanel względem jego elementu podrzędnego TextBlock .The following code example shows how to use the TransformToVisual method to retrieve the offset of the StackPanel relative to its child TextBlock. Wartości przesunięcia są zawarte w zwracanej GeneralTransform wartości.The offset values are contained within the returned GeneralTransform value.
// Return the general transform for the specified visual object.
GeneralTransform generalTransform1 = myStackPanel.TransformToVisual(myTextBlock);
// Retrieve the point value relative to the child.
Point currentPoint = generalTransform1.Transform(new Point(0, 0));
' Return the general transform for the specified visual object.
Dim generalTransform1 As GeneralTransform = myStackPanel.TransformToVisual(myTextBlock)
' Retrieve the point value relative to the child.
Dim currentPoint As Point = generalTransform1.Transform(New Point(0, 0))
Przesunięcie uwzględnia Margin wartości dla wszystkich obiektów.The offset takes into account the Margin values for all objects. W tym przypadku X jest-4, a Y to-4.In this case, X is -4, and Y is -4. Wartości przesunięcia są wartościami ujemnymi, ponieważ obiekt nadrzędny ma ujemne przesunięcie względem jego obiektu podrzędnego.The offset values are negative values because the parent object is negatively offset relative to its child object.
Uwagi
TransformToAncestorMetody i TransformToDescendant można również użyć do zwrócenia przekształcenia dla obiektu wizualnego.The TransformToAncestor and TransformToDescendant methods can also be used to return a transform for a visual object.