public static void AllVisualDescendents <T>(this FrameworkElement element, Action <FrameworkElement> action) where T : FrameworkElement { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++) { FrameworkElement frameworkElement = (FrameworkElement)VisualTreeHelper.GetChild(element, i); if (frameworkElement is T) { action(frameworkElement); } frameworkElement.AllVisualDescendents(action); } }