Skip to content

Instantly share code, notes, and snippets.

@einari
Created April 28, 2015 11:15
Show Gist options
  • Save einari/3cb5380fd8809c32d924 to your computer and use it in GitHub Desktop.
Save einari/3cb5380fd8809c32d924 to your computer and use it in GitHub Desktop.
XAML - Flatten out a UI hierarchy
private IEnumerable<UIElement> GetAllChildrenRecursively()
{
var elements = new List<UIElement>();
this.GetAllChildrenRecursively(this, elements);
return elements;
}
private void GetAllChildrenRecursively(FrameworkElement element, IList<UIElement> elements)
{
var children = LogicalTreeHelper.GetChildren(element);
foreach (var child in children)
{
if (child is UIElement)
{
elements.Add(child as UIElement);
}
if (child is FrameworkElement)
{
this.GetAllChildrenRecursively(child as FrameworkElement, elements);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment