예제 #1
0
        /// <summary>
        /// Gets the next item that should be focused in the specified container.
        /// </summary>
        /// <param name="element">The starting element/</param>
        /// <param name="container">The container.</param>
        /// <param name="direction">The direction.</param>
        /// <param name="outsideElement">
        /// If true will not descend into <paramref name="element"/> to find next control.
        /// </param>
        /// <returns>The next element, or null if the element is the last.</returns>
        private static IInputElement GetNextInContainer(
            IInputElement element,
            IInputElement container,
            NavigationDirection direction,
            bool outsideElement)
        {
            if (direction == NavigationDirection.Next && !outsideElement)
            {
                var descendant = GetFocusableDescendants(element, direction).FirstOrDefault();

                if (descendant != null)
                {
                    return(descendant);
                }
            }

            if (container != null)
            {
                var navigable = container as INavigableContainer;

                // TODO: Do a spatial search here if the container doesn't implement
                // INavigableContainer.
                if (navigable != null)
                {
                    while (element != null)
                    {
                        element = navigable.GetControl(direction, element, false);

                        if (element != null &&
                            element.CanFocus() &&
                            KeyboardNavigation.GetIsTabStop((InputElement)element))
                        {
                            break;
                        }
                    }
                }
                else
                {
                    // TODO: Do a spatial search here if the container doesn't implement
                    // INavigableContainer.
                    element = null;
                }

                if (element != null && direction == NavigationDirection.Previous)
                {
                    var descendant = GetFocusableDescendants(element, direction).LastOrDefault();

                    if (descendant != null)
                    {
                        return(descendant);
                    }
                }

                return(element);
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Gets the next item that should be focused in the specified container.
        /// </summary>
        /// <param name="element">The starting element/</param>
        /// <param name="container">The container.</param>
        /// <param name="direction">The direction.</param>
        /// <returns>The next element, or null if the element is the last.</returns>
        private static IInputElement GetNextInContainer(
            IInputElement element,
            IInputElement container,
            FocusNavigationDirection direction)
        {
            if (direction == FocusNavigationDirection.Down)
            {
                var descendent = GetFocusableDescendents(element).FirstOrDefault();

                if (descendent != null)
                {
                    return(descendent);
                }
            }

            if (container != null)
            {
                var navigable = container as INavigableContainer;

                if (navigable != null)
                {
                    while (element != null)
                    {
                        element = navigable.GetControl(direction, element);

                        if (element != null && element.CanFocus())
                        {
                            break;
                        }
                    }
                }
                else
                {
                    // TODO: Do a spatial search here if the container doesn't implement
                    // INavigableContainer.
                    element = null;
                }

                if (element != null && direction == FocusNavigationDirection.Up)
                {
                    var descendent = GetFocusableDescendents(element).LastOrDefault();

                    if (descendent != null)
                    {
                        return(descendent);
                    }
                }

                return(element);
            }

            return(null);
        }
예제 #3
0
        /// <summary>
        /// Gets the next item that should be focused in the specified container.
        /// </summary>
        /// <param name="element">The starting element/</param>
        /// <param name="container">The container.</param>
        /// <param name="direction">The direction.</param>
        /// <returns>The next element, or null if the element is the last.</returns>
        private static IInputElement GetNextInContainer(
            IInputElement element,
            IInputElement container,
            FocusNavigationDirection direction)
        {
            if (direction == FocusNavigationDirection.Down)
            {
                var descendent = GetFocusableDescendents(element).FirstOrDefault();

                if (descendent != null)
                {
                    return descendent;
                }
            }

            if (container != null)
            {
                var navigable = container as INavigableContainer;

                if (navigable != null)
                {
                    while (element != null)
                    {
                        element = navigable.GetControl(direction, element);

                        if (element != null && element.CanFocus())
                        {
                            break;
                        }
                    }
                }
                else
                {
                    // TODO: Do a spatial search here if the container doesn't implement
                    // INavigableContainer.
                    element = null;
                }

                if (element != null && direction == FocusNavigationDirection.Up)
                {
                    var descendent = GetFocusableDescendents(element).LastOrDefault();

                    if (descendent != null)
                    {
                        return descendent;
                    }
                }

                return element;
            }

            return null;
        }