Let the keyboard navigation work correctly in the Navigatioin controls. #181
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do
Before this PR, the up key and the down key do not work when the Navigation view gets focused. And after this, you can press up and down to navigate focus among the navigation items, just like what the Windows Settings and the Microsoft Store do.
KeyboardNavigation.ControlTabNavigation
attached property toOnce
manually.What changed in this PR
OnKeyDown
is overridden in theNavigationItem
class. we handle the up and down keys to navigate focus states. If the navigation happens, the Handled property is set to true to prevent further event handling. (Reason: If we do not set the Handled to true, the ScrollViewer will handle it so that the KeyboardNavigation will not do further navigation. That is why we need to do the navigation ourselves but not using the native behavior that the KeyboardNavigation provides.)OnKeyDown
is overridden in theNavigation
class. In most cases, this method does nothing because it does not receive focus by default. But if someone sets focus on it, the key handling can move the focus to its navigation children.Contained
and the tab navigation toOnce
to make sure that the focus behavior of our Navigation works just like what the Windows Settings and the Microsoft Store do. We make the control-tab navigation to keep its default value because this behavior is hard to determine in a class library.More information on the
KeyboardNavigationMode
enum can be found here: