Skip to content

Instantly share code, notes, and snippets.

@posaunehm
Created April 2, 2012 10:22
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 posaunehm/2282396 to your computer and use it in GitHub Desktop.
Save posaunehm/2282396 to your computer and use it in GitHub Desktop.
A method which returns all elements included in passed element
static IEnumerable<System.Windows.DependencyObject> EnumurateAllElement(System.Windows.DependencyObject root)
{
yield return root;
foreach (var element in GetChilren(root).SelectMany(ele => EnumurateAllElement(ele)))
{
yield return element;
}
}
static IEnumerable<System.Windows.DependencyObject> GetChilren(System.Windows.DependencyObject root)
{
for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(root); i++)
{
yield return System.Windows.Media.VisualTreeHelper.GetChild(root, i);
}
}
@posaunehm
Copy link
Author

IEnumerableは正義。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment