Skip to content

Instantly share code, notes, and snippets.

@MwBakker
Last active April 14, 2020 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MwBakker/8a417c063c023d51a4b14556300a3479 to your computer and use it in GitHub Desktop.
Save MwBakker/8a417c063c023d51a4b14556300a3479 to your computer and use it in GitHub Desktop.
public static IEnumerable<T> SelectRecursive<T>(DependencyObject involvedView, Func<T, IEnumerable<T>> selector)
{
int childrenCount = 0;
Application.Current.Dispatcher.Invoke(() => { childrenCount = VisualTreeHelper.GetChildrenCount(involvedView); });
for (var i = 0; i < childrenCount; i++)
{
foreach (T child in selector(involvedView).SelectRecursive(selector))
{
yield return child;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment