VisualTreeHelper.GetOffset(Visual) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns the offset of the Visual.
public:
static System::Windows::Vector GetOffset(System::Windows::Media::Visual ^ reference);
public static System.Windows.Vector GetOffset (System.Windows.Media.Visual reference);
static member GetOffset : System.Windows.Media.Visual -> System.Windows.Vector
Public Shared Function GetOffset (reference As Visual) As Vector
Parameters
Returns
A Vector that represents the offset value of the Visual.
Examples
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);
' 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.
Remarks
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.
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기