Created
May 1, 2023 16:57
-
-
Save 5cover/9506677440a783f30f1933724c609f4b to your computer and use it in GitHub Desktop.
FindVisualChildren C# WPF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<T> FindVisualChildren<T>(this DependencyObject depObj) where T : DependencyObject | |
{ | |
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++) | |
{ | |
var child = VisualTreeHelper.GetChild(depObj, i); | |
if (child is T t) | |
{ | |
yield return t; | |
} | |
foreach (T childOfChild in FindVisualChildren<T>(child)) | |
{ | |
yield return childOfChild; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment