Created
April 9, 2013 09:48
-
-
Save winkel/5344489 to your computer and use it in GitHub Desktop.
FindVisualChild in WinRT
This file contains hidden or 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
private T FindVisualChild<T>(DependencyObject obj) | |
where T : DependencyObject | |
{ | |
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) | |
{ | |
DependencyObject child = VisualTreeHelper.GetChild(obj, i); | |
if (child != null && child is T) | |
return (T) child; | |
else | |
{ | |
T childOfChild = FindVisualChild<T>(child); | |
if (childOfChild != null) | |
return childOfChild; | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment