語言

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回傳的偏移量。

傳回

A Vector 代表 的偏移值 Visual。

範例

以下標記範例顯示 定義 TextBlock 為 Margin 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 方法。

適用於