Visual.TransformToVisual(Visual) Visual.TransformToVisual(Visual) Visual.TransformToVisual(Visual) Method

定義

傳回轉換,這個轉換可用來將 Visual 的座標轉換為指定的視覺物件。Returns a transform that can be used to transform coordinates from the Visual to the specified visual object.

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

參數

visual
Visual Visual Visual

座標會轉換為 VisualThe Visual to which the coordinates are transformed.

傳回

例外狀況

這些視覺物件都不會產生關聯。The visual objects are not related.

範例

下列標記範例示範TextBlock中所含StackPanel物件。The following markup example shows a TextBlock that is contained within a StackPanel object.

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

下列程式碼範例示範如何使用TransformToVisual方法來擷取的位移StackPanel相對於它的子系TextBlockThe following code example shows how to use the TransformToVisual method to retrieve the offset of the StackPanel relative to its child TextBlock. 位移的值都包含在傳回GeneralTransform值。The offset values are contained within the returned GeneralTransform value.

// 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的所有物件的值。The offset takes into account the Margin values for all objects. 在此情況下,X為-4,和Y為-4。In this case, X is -4, and Y is -4. 位移的值是負數的值,因為父物件的位移負相對於其子物件。The offset values are negative values because the parent object is negatively offset relative to its child object.

備註

TransformToAncestorTransformToDescendant方法也可用來傳回視覺物件的轉換。The TransformToAncestor and TransformToDescendant methods can also be used to return a transform for a visual object.

適用於