VisualTreeHelper.GetOffset Method (Visual)
.NET Framework (current version)
Returns the offset of the Visual.
Assembly: PresentationCore (in PresentationCore.dll)
Parameters
- reference
-
Type:
System.Windows.Media.Visual
The Visual whose offset is returned.
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. Dim vector As Vector = VisualTreeHelper.GetOffset(myTextBlock) ' Convert the vector to a point value. Dim currentPoint As 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
Available since 3.0
Available since 3.0
Show: