Visual.TransformToDescendant(Visual) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳一個轉換,可用於將座標從 Visual 轉換到指定的視覺物件後代。
public:
System::Windows::Media::GeneralTransform ^ TransformToDescendant(System::Windows::Media::Visual ^ descendant);
public System.Windows.Media.GeneralTransform TransformToDescendant(System.Windows.Media.Visual descendant);
member this.TransformToDescendant : System.Windows.Media.Visual -> System.Windows.Media.GeneralTransform
Public Function TransformToDescendant (descendant As Visual) As GeneralTransform
參數
傳回
型別 GeneralTransform 的值。
例外狀況
descendant 是 null。
視覺並非視覺的 descendant 祖先。
視覺上的物件彼此無關。
範例
以下標記範例顯示 包含於物件TextBlock內的 。StackPanel
<StackPanel Name="myStackPanel" Margin="8">
<TextBlock Name="myTextBlock" Margin="4" Text="Hello, world" />
</StackPanel>
以下程式碼範例說明如何利用該TransformToDescendant方法取得相關係於子節點StackPanel的偏移量TextBlock。 偏移值包含在回傳 GeneralTransform 值中。
// Return the general transform for the specified visual object.
GeneralTransform generalTransform1 = myStackPanel.TransformToDescendant(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.TransformToDescendant(myTextBlock)
' Retrieve the point value relative to the child.
Dim currentPoint As Point = generalTransform1.Transform(New Point(0, 0))
偏移量會考慮所有物件的 Margin 數值。 此時, X 為 -4, Y 為 -4。 偏移值為負值,因為父物件相對於子物件是負偏移。