LayoutTreeHelper Class
A helper that can search for nodes in an application’s visual and logical trees.
Namespace: DevExpress.WinUI.Core
Assembly: DevExpress.WinUI.Core.v23.2.dll
NuGet Package: DevExpress.WinUI
#Declaration
#Remarks
#Retrieve an Object’s Visual Parents
Call the GetVisualParents(DependencyObject, DependencyObject) method to search for visual parents of an object that is placed in a visual or logical tree.
public static IEnumerable<DependencyObject> GetVisualParents(
DependencyObject child,
DependencyObject stopNode = null
)
This function returns a LINQ compatible collection. It allows you to use LINQ methods to access nodes of the visual and logical trees.
For example, the following code sample obtains a specific parent Grid:
var obj = LayoutTreeHelper.GetVisualParents(PART_Button as DependencyObject)
.OfType<Grid>()
.FirstOrDefault(x => x.Name == "PART_Grid");
#Retrieve an Object’s Visual Children
Call the GetVisualChildren(DependencyObject) method to search for visual children of an object that is placed in a visual tree.
To access the visual children of an object, you can use the LayoutTreeHelper.GetVisualChildren function.
public static IEnumerable<DependencyObject> GetVisualChildren(DependencyObject parent)
Similar to GetVisualParents, this function also returns a LINQ compatible collection. Thus, you can also use LINQ extension methods to obtain the required child nodes.
The code sample below obtains the child CheckBox named PART_CheckBox by using the GetVisualChildren function.
var obj = LayoutTreeHelper.GetVisualChildren(PART_Grid as DependencyObject)
.OfType<CheckBox>()
.FirstOrDefault(x => x.Name == "PART_CheckBox");