title | author | description | keywords | dev_langs | ||
---|---|---|---|---|---|---|
Visual Tree Extensions |
nmetulev |
The VisualTree extensions provide a collection of extensions methods for UI controls. It provides DependencyObject extensions to aid in using the VisualTreeHelper class (outdated docs). |
windows 10, uwp, windows community toolkit, uwp community toolkit, uwp toolkit, Visual Tree, extensions |
|
Warning
This type has been removed from the Windows Community Toolkit, please use the DependencyObjectExtensions
type instead.
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.
// Include namespace to access extensions.
using Microsoft.Toolkit.Uwp.UI.Extensions;
// 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.FindDescendants<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>();
' Include namespace to access extensions.
Imports Microsoft.Toolkit.Uwp.UI.Extensions
' Find visual descendant control using its name.
Dim control = uiElement.FindDescendantByName("MyTextBox")
' Find first visual descendant control of a specified type.
control = uiElement.FindDescendant(Of ListView)()
' Find all visual descendant controls of the specified type.
For Each child In uiElement.FindDescendants(Of ListViewItem)()
' ...
Next
' Find first visual ascendant control using its name.
control = uiElement.FindAscendantByName("MyScrollViewer")
' Find first visual ascendant control of a specified type.
control = uiElement.FindAscendant(Of ScrollViewer)()
Methods | Return Type | Description |
---|---|---|
FindAscendant<T>(this DependencyObject) | T where T : DependencyObject | Find first visual ascendant control of a specified type |
FindAscendantByName(this DependencyObject, String) | FrameworkElement | Find visual ascendant FrameworkElement control using its name |
FindDescendant<T>(this DependencyObject) | T where T : DependencyObject | Find first descendant control of a specified type |
FindDescendantByName(this DependencyObject, String) | FrameworkElement | Find descendant FrameworkElement control using its name |
FindDescendants<T>(this DependencyObject) | IEnumerable<T> where T : DependencyObject | Find all descendant controls of the specified type |
Device family | Universal, 10.0.16299.0 or higher |
---|---|
Namespace | Microsoft.Toolkit.Uwp.UI.Extensions |
NuGet package | Microsoft.Toolkit.Uwp.UI |