语言

VisualTreeHelper.GetOffset(Visual) 方法

定义

返回 . 的 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

参数

reference
Visual

Visual返回其偏移量。

返回

一个 Vector ,表示的 Visual偏移值 。

示例

以下标记示例显示了 TextBlockMargin 值 4 定义的标记。

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

下面的代码示例演示如何使用 GetOffset 该方法检索偏移 TextBlock量。 偏移值包含在返回 Vector 的值内。

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

偏移量将考虑该值 Margin 。 在本例中, X 为 4,为 Y 4。

注解

返回的偏移量值相对于的 Visual父级 。 如果要返回与父级不相对的 Visual偏移值,请使用该方法 TransformToAncestor

适用于