Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There's no provision for Alt Key Menu Bar Item activation. Keyboard Accelerators are defined at the MenuFlyoutItem level. #18782

Open
egvijayanand opened this issue Nov 16, 2023 · 4 comments
Labels
Milestone

Comments

@egvijayanand
Copy link
Contributor

egvijayanand commented Nov 16, 2023

Description

Usually, a shortcut key would be assigned for each top-level menu item (like F -> File meu, E -> Edit menu), and upon pressing the Alt key, the corresponding menu item gets activated (it gets displayed).

When the Alt key alone is pressed, the corresponding shortcut key gets highlighted in the menu bar.

In classic Windows desktop app models like WinForms, while providing the menu item text, the Ampersand char needs to be prefixed with the preferred shortcut key like &File and &Edit.

This enables us to work with the menu items using the Keyboard.

Public API Changes

A similar approach can be followed like how it's done in the classic scenario.

MenuBarItem has a Text property, the Ampersand char can be prefixed to the intended shortcut key.

Internally, while processing, the shortcut key needs to be activated by parsing the Text property.

This can be extended to MenuFlyoutItem as well so that menu items can also be activated with Keyboard.

File -> Exit as Alt + F + X for the below snippet

Since it's XAML (XML-based), the Ampersand key is encoded as &

<MenuBarItem Text="&amp;File">
  <MenuFlyoutItem Text="E&amp;xit" />
</MenuBarItem>

Intended Use-Case

This enables us to work with the menu items using the Keyboard.

The missing piece of the Keyboard Accelerators and makes it feature complete.

@egvijayanand
Copy link
Contributor Author

egvijayanand commented Nov 18, 2023

Setting the AccessKey property enables this Alt key menu activation in the WinUI desktop app.

Assuming the below XML namespace is imported for this menu code snippet.

xmlns:ui="using:Microsoft.UI.Xaml.Controls"

<ui:MenuBar>
  <ui:MenuBarItem
    Title="File"
    AccessKey="F">
    <ui:MenuFlyoutItem
      AccessKey="N"
      Text="New" />
    <ui:MenuFlyoutItem
      AccessKey="X"
      Text="Exit" />
  </ui:MenuBarItem>
</ui:MenuBar>

@egvijayanand
Copy link
Contributor Author

Have tried a sample with the AccessKey property and it worked fine for the WinUI app. Will upload the sample to my GitHub repo and share the URL.

Here's the screenshot.

image

@egvijayanand
Copy link
Contributor Author

Sample app now made available here: https://github.com/egvijayanand/maui-issue-18782

@egvijayanand
Copy link
Contributor Author

egvijayanand commented Nov 27, 2023

Have tried to make use of this Alt key mnemonic feature with a variety of controls (Button. CheckBox, Entry), it works like a charm and it'll prove to be a great value addition to the Desktop apps.

On the Windows platform, the AccessKey property is defined at the UIElement level, so it can be applied to any Visual control. The property needs to be defined at the appropriate base control in .NET MAUI so those dummy interfaces and classes can be removed from the sample.

Have pushed the newer version of the source to the same repo.

Here's the updated screenshot:

image

@jsuarezruiz @davidortinau @maddymontaquila

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants