Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
This topic has not yet been rated - Rate this topic

VisualTreeHelper.GetTransform Method

Returns a Transform value for the Visual.

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

public static Transform GetTransform (
	Visual reference
)
public static Transform GetTransform (
	Visual reference
)
public static function GetTransform (
	reference : Visual
) : Transform
You cannot use methods in XAML.

Parameters

reference

The Visual whose transform value is returned.

Return Value

The transform value of the Visual, or a null reference (Nothing in Visual Basic) 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.
GeneralTransform generalTransform1 = myTextBlock.TransformToAncestor((Visual)myTextBlock.Parent);

// Retrieve the point value relative to the parent.
Point currentPoint = 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.
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));
}

Your code should test for a null reference (Nothing in Visual Basic) 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.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.