Visual.TransformToVisual Method
Returns a transform that can be used to transform coordinates from the Visual to the specified visual object.
Assembly: PresentationCore (in PresentationCore.dll)
Parameters
- visual
- Type: System.Windows.Media.Visual
The Visual to which the coordinates are transformed.
| Exception | Condition |
|---|---|
| ArgumentNullException | visual is a null reference (Nothing in Visual Basic). |
| InvalidOperationException | The visual objects are not related. |
The TransformToAncestor and TransformToDescendant methods can also be used to return a transform for a visual object.
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>
The following code example shows how to use the TransformToVisual method to retrieve the offset of the StackPanel relative to its child TextBlock. The offset values are contained within the returned GeneralTransform value.
The offset takes into account the Margin values for all objects. 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.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.