/// <summary> /// Gets the next control in the specified navigation direction. /// </summary> /// <param name="element">The element.</param> /// <param name="direction">The navigation direction.</param> /// <returns> /// The next element in the specified direction, or null if <paramref name="element"/> /// was the last in the requested direction. /// </returns> public static IInputElement?GetNext( IInputElement element, NavigationDirection direction) { element = element ?? throw new ArgumentNullException(nameof(element)); // If there's a custom keyboard navigation handler as an ancestor, use that. var custom = element.FindAncestorOfType <ICustomKeyboardNavigation>(true); if (custom is object && HandlePreCustomNavigation(custom, element, direction, out var ce)) { return(ce); } var result = direction switch { NavigationDirection.Next => TabNavigation.GetNextTab(element, false), NavigationDirection.Previous => TabNavigation.GetPrevTab(element, null, false), _ => throw new NotSupportedException(), }; // If there wasn't a custom navigation handler as an ancestor of the current element, // but there is one as an ancestor of the new element, use that. if (custom is null && HandlePostCustomNavigation(element, result, direction, out ce)) { return(ce); } return(result); }