avalonia-docs icon indicating copy to clipboard operation
avalonia-docs copied to clipboard

MenuItems should display their HotKeys

Open yshklarov opened this issue 1 year ago • 6 comments

The problem

Menus in Windows applications typically display their associated hotkeys, right-aligned, as part of the menu's header. Otherwise, the HotKey is not discoverable, which makes the HotKey useless in practice in many cases.

Request

It should be possible (in fact, it should be the default) for a MenuItem to display its HotKey to the right of the Header.

Workaround

For now, the HotKey can be manually added in parentheses at the end of the Header. However, this is ugly because it's not right-aligned (and tab stops don't work here).

Example

Here's the main menu in Firefox. The hotkeys can be seen to the right of each menu header. image

yshklarov avatar Feb 06 '24 05:02 yshklarov

Avalonia already supports this. You can assign InputGesture for each MenuItem. Attached is my own theme but Fluent/Simple theme should also support this. image

rabbitism avatar Feb 06 '24 05:02 rabbitism

Oh, excellent, thank you!

May I suggest that the MenuItem's InputGesture and HotKey properties' API reference pages link to each other to make this more clear?

yshklarov avatar Feb 06 '24 06:02 yshklarov

There is also a convention way of doing this. Which is to put a _ at the start of the header text. EG _File will make the hot key set to F as that's the first letter in the string. The _ will be automatically removed. It will show up if you press ALT with the menu focused. It's fairly useful if you have a simple menu.

https://docs.avaloniaui.net/docs/reference/controls/menu

thevortexcloud avatar Feb 06 '24 07:02 thevortexcloud

There is also a convention way of doing this. Which is to put a _ at the start of the header text. EG _File will make the hot key set to F as that's the first letter in the string. The _ will be automatically removed. It will show up if you press ALT with the menu focused. It's fairly useful if you have a simple menu.

https://docs.avaloniaui.net/docs/reference/controls/menu

This is useful, too, but it's not quite the same thing. A HotKey can be used without pressing Alt and bringing the menu open. A HotKey is something like Ctrl-S to save the current document, which is distinct from the "accelerator" Alt-F → S that performs the same command. Many menu commands need to have both.

yshklarov avatar Feb 06 '24 07:02 yshklarov

Ah right, I misread your post. My bad.

thevortexcloud avatar Feb 06 '24 07:02 thevortexcloud

@yshklarov sounds like it's a docs issue then. So I'll move it there.

timunie avatar Feb 06 '24 07:02 timunie