Example #1
0
        /// <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 therequested direction.
        /// </returns>
        public static IInputElement GetNext(
            IInputElement element,
            FocusNavigationDirection direction)
        {
            Contract.Requires <ArgumentNullException>(element != null);

            if (direction == FocusNavigationDirection.Next || direction == FocusNavigationDirection.Previous)
            {
                return(TabNavigation.GetNextInTabOrder(element, direction));
            }
            else
            {
                return(DirectionalNavigation.GetNext(element, direction));
            }
        }
Example #2
0
        /// <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)
        {
            Contract.Requires <ArgumentNullException>(element != null);

            var customHandler = element.GetSelfAndVisualAncestors()
                                .OfType <ICustomKeyboardNavigation>()
                                .FirstOrDefault();

            if (customHandler != null)
            {
                var(handled, next) = customHandler.GetNext(element, direction);

                if (handled)
                {
                    if (next != null)
                    {
                        return(next);
                    }
                    else if (direction == NavigationDirection.Next || direction == NavigationDirection.Previous)
                    {
                        return(TabNavigation.GetNextInTabOrder((IInputElement)customHandler, direction, true));
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            if (direction == NavigationDirection.Next || direction == NavigationDirection.Previous)
            {
                return(TabNavigation.GetNextInTabOrder(element, direction));
            }
            else
            {
                throw new NotSupportedException();
            }
        }