Added KeyDown Event Handler for NavPane

This commit is contained in:
achmurali 2021-04-17 00:15:27 +05:30
commit b24a784ece
3 changed files with 18 additions and 0 deletions

View file

@ -168,6 +168,7 @@
PaneOpened="OnNavPaneOpened" PaneOpened="OnNavPaneOpened"
PaneOpening="OnNavPaneOpening" PaneOpening="OnNavPaneOpening"
SelectionChanged="OnNavSelectionChanged" SelectionChanged="OnNavSelectionChanged"
KeyDown="OnNavPaneKeyDown"
TabIndex="1" TabIndex="1"
UseSystemFocusVisuals="True" UseSystemFocusVisuals="True"
IsEnabled="{x:Bind Model.IsAlwaysOnTop, Converter={StaticResource BooleanNegationConverter}, Mode=OneWay}" IsEnabled="{x:Bind Model.IsAlwaysOnTop, Converter={StaticResource BooleanNegationConverter}, Mode=OneWay}"

View file

@ -427,6 +427,22 @@ void MainPage::OnNavPaneClosed(_In_ MUXC::NavigationView ^ sender, _In_ Object ^
this->SetDefaultFocus(); this->SetDefaultFocus();
} }
void MainPage::OnNavPaneKeyDown(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e)
{
if (e->Key == VirtualKey::Space || e->Key == VirtualKey::Enter)
{
auto item = dynamic_cast<MUXC::NavigationViewItem ^>(FocusManager::GetFocusedElement());
if (item != nullptr && item->Name != L"About")
{
auto selectedItem = static_cast<NavCategory ^>(item->DataContext);
Model->Mode = selectedItem->Mode;
NavView->SelectedItem = item;
NavView->IsPaneOpen = false;
}
}
}
void MainPage::OnAboutButtonClick(Object ^ sender, ItemClickEventArgs ^ e) void MainPage::OnAboutButtonClick(Object ^ sender, ItemClickEventArgs ^ e)
{ {
ShowAboutPage(); ShowAboutPage();

View file

@ -53,6 +53,7 @@ public
void OnNavItemInvoked( void OnNavItemInvoked(
Microsoft::UI::Xaml::Controls::NavigationView ^ /*sender*/, Microsoft::UI::Xaml::Controls::NavigationView ^ /*sender*/,
_In_ Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs ^ e); _In_ Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs ^ e);
void OnNavPaneKeyDown(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e);
void OnAboutButtonClick(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Controls::ItemClickEventArgs ^ e); void OnAboutButtonClick(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Controls::ItemClickEventArgs ^ e);
void OnAboutButtonKeyDown(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e); void OnAboutButtonKeyDown(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e);