Skip to content

Instantly share code, notes, and snippets.

@winkel
Created April 9, 2013 09:48
Show Gist options
  • Save winkel/5344489 to your computer and use it in GitHub Desktop.
Save winkel/5344489 to your computer and use it in GitHub Desktop.
FindVisualChild in WinRT
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