Export (0) Print
Expand All
0 out of 3 rated this helpful - Rate this topic

Visual.TransformToVisual 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)

public GeneralTransform TransformToVisual (
	Visual visual
)
public GeneralTransform TransformToVisual (
	Visual visual
)
public function TransformToVisual (
	visual : Visual
) : GeneralTransform
You cannot use methods in XAML.

Parameters

visual

The Visual to which the coordinates are transformed.

Return Value

A value of type GeneralTransform.
Exception typeCondition

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.

// 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, since the parent object is negatively offset relative to its child object.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.