avalonia-docs
avalonia-docs copied to clipboard
MenuItems should display their HotKeys
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.
Avalonia already supports this. You can assign InputGesture for each MenuItem.
Attached is my own theme but Fluent/Simple theme should also support this.
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?
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
There is also a convention way of doing this. Which is to put a
_at the start of the header text. EG_Filewill make the hot key set toFas 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.
Ah right, I misread your post. My bad.
@yshklarov sounds like it's a docs issue then. So I'll move it there.