Visual.TransformToVisual(Visual) 方法
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回轉換,這個轉換可用來將 Visual 的座標轉換為指定的視覺物件。
public:
System::Windows::Media::GeneralTransform ^ TransformToVisual(System::Windows::Media::Visual ^ visual);
C#
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
型別 GeneralTransform 的值。
visual
為 null
。
這些視覺物件都不會產生關聯。
下列標記範例顯示 TextBlock 包含在 物件內的 StackPanel 。
XAML
<StackPanel Name="myStackPanel" Margin="8">
<TextBlock Name="myTextBlock" Margin="4" Text="Hello, world" />
</StackPanel>
下列程式碼範例示範如何使用 TransformToVisual 方法來擷取相對於其子 TextBlock 的 StackPanel 位移。 位移值包含在傳 GeneralTransform 回的值內。
C#
// 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 方法也可以用來傳回視覺物件的轉換。
產品 | 版本 |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |