Skip to main content
.NET Framework Class Library
VisualTransformToVisual Method

Returns a transform that can be used to transform coordinates from the Visual to the specified visual object.

Namespace:   System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)
Syntax
Public Function TransformToVisual ( _
	visual As [%$TOPIC/ms608867_en-us_VS_110_2_0_0_0_0%] _
) As [%$TOPIC/ms608867_en-us_VS_110_2_0_0_0_1%]
public [%$TOPIC/ms608867_en-us_VS_110_2_0_1_0_0%] TransformToVisual(
	[%$TOPIC/ms608867_en-us_VS_110_2_0_1_0_1%] visual
)
public:
[%$TOPIC/ms608867_en-us_VS_110_2_0_2_0_0%]^ TransformToVisual(
	[%$TOPIC/ms608867_en-us_VS_110_2_0_2_0_1%]^ visual
)
member TransformToVisual : 
        visual:[%$TOPIC/ms608867_en-us_VS_110_2_0_3_0_0%] -> [%$TOPIC/ms608867_en-us_VS_110_2_0_3_0_1%]

Parameters

visual
Type: System.Windows.MediaVisual

The Visual to which the coordinates are transformed.

Exceptions
ExceptionCondition
ArgumentNullException

visual is .

InvalidOperationException

The visual objects are not related.

Remarks

The TransformToAncestor and TransformToDescendant methods can also be used to return a transform for a visual object.

Examples

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.

			' 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))
// 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));

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.

Version Information

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.