ms.date: 08/20/2017 description: The VisualTree extensions provide a collection of extensions methods for UI controls. It provides DependencyObject extensions to aid in using the VisualTreeHelper class. keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, Visual Tree, extentions


Visual Tree Extensions

The VisualTree extensions provide a collection of extensions methods for UI controls.

It provides DependencyObject extensions to aid in using the VisualTreeHelper class. The official VisualTreeHelper documentation best explains reasons for walking the Visual Tree.

See also LogicalTree Extensions.

Example


    // Include namespace to access extensions.
    using Microsoft.Toolkit.Uwp.UI;

    // Find visual descendant control using its name.
    var control = uiElement.FindDescendantByName("MyTextBox");

    // Find first visual descendant control of a specified type.
    control = uiElement.FindDescendant<ListView>();

    // Find all visual descendant controls of the specified type.
    foreach (var child in uiElement.FindDescendant<ListViewItem>())
    {
        // ...
    }

    // Find first visual ascendant control using its name.
    control = uiElement.FindAscendantByName("MyScrollViewer");

    // Find first visual ascendant control of a specified type.
    control = uiElement.FindAscendant<ScrollViewer>();

Requirements (Windows 10 Device Family)

Device family Universal, 10.0.14393.0 or higher
Namespace Microsoft.Toolkit.Uwp.UI.Extensions

API