Skip to content

Instantly share code, notes, and snippets.

@peterfoot
Created March 10, 2022 10:01
Show Gist options
  • Save peterfoot/296548c8910525990e0f8f1223b9fd10 to your computer and use it in GitHub Desktop.
Save peterfoot/296548c8910525990e0f8f1223b9fd10 to your computer and use it in GitHub Desktop.
Add AccessKeys to standard NavigationView elements
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
namespace InTheHand.UI.Xaml.Controls
{
public static class NavigationViewHelper
{
/// <summary>
/// Add standard access keys to the NavigationView control.
/// </summary>
/// <remarks>These are based on Microsoft Your Phone, there isn't a standard implementation across all NavigationView based apps.</remarks>
/// <param name="navigationView"></param>
public static void SetAccessKeys(this NavigationView navigationView)
{
// access key to show/hide navigation pane
navigationView.AccessKey = "H";
navigationView.KeyTipPlacementMode = KeyTipPlacementMode.Right;
// access key to open Settings item
var settingsItem = navigationView.SettingsItem as NavigationViewItem;
settingsItem.AccessKey = "S";
settingsItem.KeyTipPlacementMode = KeyTipPlacementMode.Right;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment