Export (0) Print
Expand All

Visual.TransformToDescendant Method

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

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)

public GeneralTransform TransformToDescendant(
	Visual descendant
)
You cannot use methods in XAML.

Parameters

descendant
Type: System.Windows.Media.Visual

The Visual to which the coordinates are transformed.

ExceptionCondition
ArgumentNullException

descendant is null.

ArgumentException

The visual is not an ancestor of the descendant visual.

InvalidOperationException

The visual objects are not related.

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 TransformToDescendant 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.TransformToDescendant(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.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5, 3.0

Community Additions

ADD
Show:
© 2014 Microsoft