VisualTreeHelper.GetOffset Method

Returns the offset of the Visual.

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

public static Vector GetOffset(
	Visual reference
)

Parameters

reference
Type: System.Windows.Media.Visual

The Visual whose offset is returned.

Return Value

Type: System.Windows.Vector
A Vector that represents the offset value of the Visual.

The returned offset value is relative to the parent of the Visual. If you want to return an offset value that is not relative to the parent of a Visual, use the TransformToAncestor method.

The following markup example shows a TextBlock that is defined with Margin value of 4.

<TextBlock Name="myTextBlock" Margin="4" Text="Hello, world" />

The following code example shows how to use the GetOffset method to retrieve the offset of the TextBlock. The offset values are contained within the returned Vector value.

// Return the offset vector for the TextBlock object.
Vector vector = VisualTreeHelper.GetOffset(myTextBlock);

// Convert the vector to a point value.
Point currentPoint = new Point(vector.X, vector.Y);

The offset takes into account the Margin value. In this case, X is 4, and Y is 4.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft