Exemple #1
0
        /// <summary>
        /// Navigates to next (down) item or directional focus object if possible on key input
        /// </summary>
        /// <param name="e">EventArgs describing key input</param>
        private void NavigateDown(KeyEventArgs e)
        {
            ApplicationNavigationAction action = GetApplicationNavigationActionForKeyEvent(e);

            if (action != ApplicationNavigationAction.None)
            {
                switch (action)
                {
                case ApplicationNavigationAction.NavigateFromSection:
                    GoToNextSection();
                    e.Handled = true;
                    break;

                case ApplicationNavigationAction.NavigateFromStory:
                    // Execute NextPage command for StoryViewer, which is configured to go to next story if next page cannot execute
                    StoryViewer storyViewer = Keyboard.FocusedElement as StoryViewer;
                    if (storyViewer != null)
                    {
                        if (System.Windows.Input.NavigationCommands.NextPage.CanExecute(null, storyViewer))
                        {
                            System.Windows.Input.NavigationCommands.NextPage.Execute(null, storyViewer);
                        }
                        e.Handled = true;
                    }
                    break;

                default:
                    break;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Navigates to next (right) item or directional focus object if possible on key input
        /// </summary>
        /// <param name="e">EventArgs describing key input</param>
        private void NavigateRight(KeyEventArgs e)
        {
            ApplicationNavigationAction action = GetApplicationNavigationActionForKeyEvent(e);

            if (action != ApplicationNavigationAction.None)
            {
                switch (action)
                {
                case ApplicationNavigationAction.NavigateFromSection:
                case ApplicationNavigationAction.NavigateFromStory:
                    GoToNextStory();
                    e.Handled = true;
                    break;

                default:
                    break;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Gets the appropriate navigation action for key input
        /// </summary>
        /// <returns>Navigation action to perform for the key input</returns>
        private ApplicationNavigationAction GetApplicationNavigationActionForKeyEvent(KeyEventArgs e)
        {
            ApplicationNavigationAction action = ApplicationNavigationAction.None;

            switch (e.Key)
            {
            case Key.Left:
            case Key.Right:
            case Key.Up:
            case Key.Down:
            case Key.I:
            case Key.J:
            case Key.K:
            case Key.M:
            case Key.Space:
            case Key.PageDown:
            case Key.PageUp:
                if (ServiceProvider.ViewManager.CurrentNavigator is SectionNavigator)
                {
                    if (ServiceProvider.ViewManager.CurrentNavigator is ReadingListNavigator ||
                        ServiceProvider.ViewManager.CurrentNavigator is SearchNavigator)
                    {
                        // For reading list and search UI, the main content visual is not focusable, and won't have the focus
                        // Since this UI is application-based (unlike SectionFrontControl) the application can choose to handle
                        // navigation keys regardless of what the event source is. For these sections, the application does not
                        // handle up or down keys, since they are not connected to other sections and up and down should
                        // navigate reading list items/ search results. But left and right keys navigate stories
                        if (e.Key == Key.Left || e.Key == Key.Right)
                        {
                            action = ApplicationNavigationAction.NavigateFromSection;
                        }
                    }
                    else
                    {
                        // Sections don't have a fixed template, may be different for search, reading list, etc
                        // In general, check that source is the current content visual, section fronts are a special case because they steal
                        // focus from the current content visual
                        // Application authors may change this code to recognize their custom controls for focus manipulation
                        UIElement source = e.OriginalSource as UIElement;
                        UIElement currentContentVisual = ServiceProvider.ViewManager.CurrentVisual as UIElement;
                        if (currentContentVisual != null && source != null)
                        {
                            if (source == currentContentVisual || source is SectionFrontControl)
                            {
                                action = ApplicationNavigationAction.NavigateFromSection;
                            }
                        }
                    }
                }
                else if (ServiceProvider.ViewManager.CurrentNavigator is StoryNavigator)
                {
                    // Check that a StoryViewer is focused, since annotation layer may be topmost in stories if user is making notes
                    // In such a case navigation should not take place on key input
                    if (e.OriginalSource is StoryViewer)
                    {
                        action = ApplicationNavigationAction.NavigateFromStory;
                    }
                }
                break;

            default:
                break;
            }
            return(action);
        }