語言

Visual.TransformToVisual(Visual) 方法

定義

回傳一個轉換,可用於將座標從 Visual 轉換到指定的視覺物件。

public:
 System::Windows::Media::GeneralTransform ^ TransformToVisual(System::Windows::Media::Visual ^ visual);
public System.Windows.Media.GeneralTransform TransformToVisual(System.Windows.Media.Visual visual);
member this.TransformToVisual : System.Windows.Media.Visual -> System.Windows.Media.GeneralTransform
Public Function TransformToVisual (visual As Visual) As GeneralTransform

參數

visual
Visual

座標 Visual 會被轉換到。

傳回

型別 GeneralTransform 的值。

例外狀況

visual 是 null。

視覺上的物件彼此無關。

範例

以下標記範例顯示 包含於物件TextBlock內的 。StackPanel

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

以下程式碼範例說明如何利用該TransformToVisual方法取得相關係於子節點StackPanel的偏移量TextBlock。 偏移值包含在回傳 GeneralTransform 值中。

// Return the general transform for the specified visual object.
GeneralTransform generalTransform1 = myStackPanel.TransformToVisual(myTextBlock);

// Retrieve the point value relative to the child.
Point currentPoint = generalTransform1.Transform(new Point(0, 0));
' Return the general transform for the specified visual object.
Dim generalTransform1 As GeneralTransform = myStackPanel.TransformToVisual(myTextBlock)

' Retrieve the point value relative to the child.
Dim currentPoint As Point = generalTransform1.Transform(New Point(0, 0))

偏移量會考慮所有物件的 Margin 數值。 此時, X 為 -4, Y 為 -4。 偏移值為負值,因為父物件相對於子物件是負偏移。

備註

TransformToAncestor和 TransformToDescendant 方法也可以用來回傳視覺物件的變換。

適用於