Skip to content

Instantly share code, notes, and snippets.

@jozsef-vesza
Created May 22, 2015 09:11
Show Gist options
  • Save jozsef-vesza/493c11178177aa2d0832 to your computer and use it in GitHub Desktop.
Save jozsef-vesza/493c11178177aa2d0832 to your computer and use it in GitHub Desktop.
public static IEnumerable<T> FindVisualChildren<T>(this DependencyObject e) where T : DependencyObject
{
if (e == null) yield break;
VisualTreeHelper.GetChildren(e).Filter(child is T).Map(child => ()
{
if (children != null)
{
yield return children;
}
foreach (var 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