private ChildType FindVisualChild<ChildType>(DependencyObject obj) where ChildType : DependencyObject { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) { DependencyObject child = VisualTreeHelper.GetChild(obj,i); if (child!=null&& child is ChildType) { return child as ChildType; } else { ChildType childOfChildren = FindVisualChild<ChildType>(child); if (childOfChildren!=null) { return childOfChildren; } } } return null; }