/// <summary> /// Enumerates through the descendats of the given <c>parent</c>, performing a 'breadth first' search /// </summary> public static IEnumerable <TYpe> GetVisualDescendantsBreadthFirst <TYpe>(this DependencyObject parent) where TYpe : class { int ChildrenCount = VisualTreeHelper.GetChildrenCount(parent); for (int Index = 0; Index < ChildrenCount; Index++) { DependencyObject Child = VisualTreeHelper.GetChild(parent, Index); if (Child is TYpe) { yield return(Child as TYpe); } } for (int Index = 0; Index < ChildrenCount; Index++) { DependencyObject Child = VisualTreeHelper.GetChild(parent, Index); foreach (TYpe Descendant in VisualTreeHelperEx.GetVisualDescendantsBreadthFirst <TYpe>(Child)) { yield return(Descendant); } } }
///<summary> /// Returns the bounds of the element, at location within reference ///</summary> public static Rect GetBounds(Visual reference, Visual uiElement) { Rect Bounds = VisualTreeHelperEx.GetBounds(uiElement); return(uiElement.TransformToVisual(reference).TransformBounds(Bounds)); }