internal static IEnumerable <T> FindChildrenByType <T>(this DependencyObject element) where T : DependencyObject { return(element.ChildrenOfType <T>()); }
/// <summary> /// Does a deep search of the element tree, trying to find a descendant of the given type /// (including the element itself). /// </summary> /// <returns>True if the target is one of the elements.</returns> internal static T GetFirstDescendantOfType <T>(this DependencyObject target) where T : DependencyObject { return(target as T ?? target.ChildrenOfType <T>().FirstOrDefault()); }
/// <summary> /// Finds child element of the specified type. Uses breadth-first search. /// </summary> /// <typeparam name="T"> /// The type of the child that will be searched in the object hierarchy. The type should be <see cref="DependencyObject"/>. /// </typeparam> /// <param name="element">The target <see cref="DependencyObject"/> which children will be traversed.</param> /// <returns>The first child element that is of the specified type.</returns> public static T FindChildByType <T>(this DependencyObject element) where T : DependencyObject { return(element.ChildrenOfType <T>().FirstOrDefault()); }