public static Visual FindDescendantByType(Visual element, Type type, bool specificTypeOnly) { if (element == null) { return(null); } if (specificTypeOnly ? (element.GetType() == type) : (element.GetType() == type) || (element.GetType().IsSubclassOf(type))) { return(element); } Visual foundElement = null; if (element is FrameworkElement) { (element as FrameworkElement).ApplyTemplate(); } for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++) { Visual visual = VisualTreeHelper.GetChild(element, i) as Visual; foundElement = VisualTreeHelperEx.FindDescendantByType(visual, type, specificTypeOnly); if (foundElement != null) { break; } } return(foundElement); }
public static Visual FindDescendantByType(Visual element, Type type) { return(VisualTreeHelperEx.FindDescendantByType(element, type, true)); }
public static T FindDescendantByType <T>(Visual element) where T : Visual { Visual temp = VisualTreeHelperEx.FindDescendantByType(element, typeof(T)); return((T)temp); }