VisualTreeHelper.GetTransform Method

Returns a Transform value for the Visual.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)

'Declaration
Public Shared Function GetTransform ( _
	reference As Visual _
) As Transform

Parameters

reference
Type: System.Windows.Media.Visual

The Visual whose transform value is returned.

Return Value

Type: System.Windows.Media.Transform
The transform value of the Visual, or Nothing if reference does not have a transform defined.

Alternatively, you can use the TransformToAncestor method to return a transform value for the ancestor of a Visual. This method always returns a valid transform. The following code example shows how to use TransformToAncestor method.

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

The following code example shows how to use the GetTransform method to retrieve the transform for the specified visual object.

			' 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

Your code should test for Nothing before using the returned value. To return the offset of the returned transform, use the Transform method. The offset value is relative to the parent of the Visual.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft