The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Visual.TransformToVisual Method (Visual)


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)

member TransformToVisual : 
        visual:Visual -> GeneralTransform


Type: System.Windows.Media.Visual

The Visual to which the coordinates are transformed.

Return Value

Type: System.Windows.Media.GeneralTransform

A value of type GeneralTransform.

Exception Condition

visual is null.


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" />

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.

No code example is currently available or this language may not be supported.

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.

.NET Framework
Available since 3.0
Return to top
© 2015 Microsoft