private static bool HandlePreCustomNavigation(
            ICustomKeyboardNavigation customHandler,
            IInputElement element,
            NavigationDirection direction,
            [NotNullWhen(true)] out IInputElement?result)
        {
            if (customHandler != null)
            {
                var(handled, next) = customHandler.GetNext(element, direction);

                if (handled)
                {
                    if (next != null)
                    {
                        result = next;
                        return(true);
                    }
                    else if (direction == NavigationDirection.Next || direction == NavigationDirection.Previous)
                    {
                        var r = direction switch
                        {
                            NavigationDirection.Next => TabNavigation.GetNextTabOutside(customHandler),
                            NavigationDirection.Previous => TabNavigation.GetPrevTabOutside(customHandler),
                            _ => throw new NotSupportedException(),
                        };

                        if (r is object)
                        {
                            result = r;
                            return(true);
                        }
                    }
                }
            }

            result = null;
            return(false);
        }