Class WPFUIHelper
- Namespace
- VisioForge.Core.UI.WPF
- Assembly
- VisioForge.Core.dll
Static utility class providing WPF visual tree manipulation and search functionality.
This helper class offers essential tools for navigating and manipulating the WPF visual tree, which is crucial for finding child controls, implementing custom behaviors, and performing runtime UI analysis. Particularly useful for control templating, theming, and dynamic UI scenarios.
Key features:
- Recursive visual tree traversal with generic type filtering
- Efficient enumeration of specific control types
- Deep searching through complex visual hierarchies
- Support for finding controls within templates and data templates
- Performance-optimized iteration with yield return
Common use cases:
- Finding specific controls within complex UI hierarchies
- Implementing custom behaviors that need to locate child controls
- Theming and styling operations that require control enumeration
- Debugging and diagnostics for UI structure analysis
- Dynamic UI generation requiring control discovery
Performance characteristics:
- Uses yield return for memory-efficient iteration
- Recursive traversal with early termination support
- Minimal memory allocation during traversal
- Optimized for both shallow and deep tree searches
Thread safety: All methods should be called from the UI thread as they manipulate WPF visual elements.
public class WPFUIHelperInheritance
Inherited Members
Methods
FindVisualChildren<T>(DependencyObject)
Recursively finds all visual children of a specific type within the WPF visual tree.
This method performs a depth-first search through the visual tree starting from the specified dependency object, returning all child objects that match the generic type constraint. Uses yield return for memory-efficient iteration over large visual trees.
Search behavior:
- Performs recursive depth-first traversal
- Filters results by generic type constraint
- Includes the starting object if it matches the type
- Searches through all visual children and their descendants
- Handles null references gracefully
Performance characteristics:
- Lazy evaluation through yield return
- Memory-efficient for large trees
- Early termination support when used with LINQ
- Minimal allocation overhead
Common usage patterns:
- Finding all Button controls: FindVisualChildren<Button>(panel)
- Locating TextBox controls: FindVisualChildren<TextBox>(form)
- Enumerating custom controls: FindVisualChildren<MyControl>(container)
Thread safety: Must be called from the UI thread as it traverses WPF visual elements.
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObjectParameters
depObjDependencyObject-
The root dependency object to start searching from.
Returns
- IEnumerable<T>
-
An enumerable collection of all visual children matching the specified type.
Type Parameters
T-
The type of visual children to find (must derive from DependencyObject).