public static IEnumerable <View> EnumerateAllChildrenReverse(this ViewGroup view, Func <View, bool> selector, int maxDepth = 20) { foreach (var sub in view.GetChildrenReverse()) { if (selector(sub)) { yield return(sub); } else if (maxDepth > 0) { if (sub is ViewGroup childGroup) { foreach (var subResult in childGroup.EnumerateAllChildrenReverse(selector, maxDepth - 1)) { yield return(subResult); } } } } }