Skip to main content

Open-WebUI-Functions is here! New Pipelines, Filters, and more. Learn more

WinUI Keyboard Accelerator Patterns

Keyboard accelerators let users trigger common actions without leaving the keyboard. They improve efficiency for power users and provide alternate access paths for assistive technologies.

Learn more

Overview

  • Accelerators can be attached to any focusable control through the KeyboardAccelerators collection.
  • When multiple handlers match, precedence is UIElementAppCoreWindow, so scope them carefully.
  • Use ScopeOwner to limit accelerators to a specific section (for example, a dialog) without affecting the rest of the window.

Prerequisites

  • WinUI 3 project targeting Windows 10 version 1809 or later
  • Reference to Microsoft.UI.Xaml.Input.KeyboardAccelerator
  • Clear command naming conventions to avoid collisions with system shortcuts

Register scoped accelerators

The example below assigns Ctrl+F to a search box while allowing the accelerator to bubble to the page when focus is elsewhere.

Use KeyboardAcceleratorPlacementMode to control whether tooltips expose the shortcut automatically. This helps discoverability without building custom tooltip strings.

Best practices

  • Avoid conflicts: Reserve common shortcuts (Ctrl+C, Ctrl+V, Ctrl+S) for their standard meanings unless your experience is very specialized.
  • Accessibility: Document shortcuts in your help content and ensure alternate mouse/touch paths exist for every action.
  • Security: Avoid binding accelerators to operations that mutate sensitive data without confirmation to prevent accidental triggers.
  • Testing: Verify accelerators under high contrast mode and with screen readers; make sure focus moves to relevant UI before executing commands.