Created
April 2, 2012 10:22
-
-
Save posaunehm/2282396 to your computer and use it in GitHub Desktop.
A method which returns all elements included in passed element
This file contains 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
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IEnumerableは正義。