Skip to content

Latest commit

 

History

History
49 lines (30 loc) · 4.31 KB

uielement_transformtovisual_799251735.md

File metadata and controls

49 lines (30 loc) · 4.31 KB
-api-id -api-type
M:Windows.UI.Xaml.UIElement.TransformToVisual(Windows.UI.Xaml.UIElement)
winrt method

Windows.UI.Xaml.UIElement.TransformToVisual

-description

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

-parameters

-param visual

The object to compare to the current object for purposes of obtaining the transform. If this parameter is null, then the root of the XAML tree is used.

-returns

The transform information as an object. Call methods on this object to get a practical transform.

-remarks

Call TransformToVisual in order to get a coordinate offset between two elements in a UI. The first element being considered is the UIElement where you call TransformToVisual, the second element is the UIElement you pass as the visual parameter. For example, you can use the transform to determine how the bounds of an element are positioned in a coordinate system that is relative to a layout parent element, rather than the app's window.

TransformToVisual gives coordinate results after all considerations that affect rendering and positioning such as RenderTransform have been applied. This is useful if you're processing point values that were obtained during an animation of RenderTransform or other position changes.

The most common scenario for TransformToVisual is if you want to use a local coordinate system relative to the UIElement you call it on, and you aren't handling a real-time input event that has event data methods for converting a Point value into the object's frame of reference. After you call TransformToVisual, you can then call TransformPoint on the returned GeneralTransform.

Note

The GeneralTransform object returned by this method can be cast to a derived type, Transform, but all the methods you need are defined by GeneralTransform. You can't cast to TranslateTransform even though you might expect that the transform result would be a translation.

-examples

This example shows a scenario for calling TransformToVisual in order to interpret the coordinates from a PointerPoint in the coordinate reference frame of an element that's not the event sender. Here, the queryPointer method first accesses coordinates that do relate to the sender (this is the GetCurrentPoint call in the first line of the method) but then later uses TransformToVisual to convert point coordinates into the reference frame for the page layout container that's actually several layers of containment up in the XAML. To see more context for this code (including seeing how queryPointer displays results in UI and when it's called), see the complete code example that is shown in the topic Handle pointer input.

[!code-xamlUI]

[!code-xamlUI]

[!code-csharpQueryPointer]

[!code-csharpQueryPointer]

-see-also

GeneralTransform, Define layouts with XAML, XAML two-dimensional transforms sample