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

要傳回其位移 (Offset) 的 Visual

傳回

Vector

Vector,表示 Visual 的位移值。

範例

下列標記範例顯示 TextBlock 以 4 值定義的 Margin

<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 方法。

適用於