This project is read-only.

Menu "hot" keys

May 22, 2013 at 6:02 AM

It used to be that if we preceeded a menu item with "&", it would result in the next character getting an underline and responding to shortcut keys. We could also define a keyboard shortcut such as CTRL-P, etc. that would accomplish the same thing.

I have tried _, \, /, *, -, and !, but none of these accomplish this. Nor can I find a way to tie in the CTRL key to the menu.

Can you give me a hint as to what I need to do to support these 2 items?


May 24, 2013 at 6:04 AM
Edited May 24, 2013 at 6:04 AM
WPF uses the underscore key to indicate that the next char is meant to be the hotkey. So if you set the action's text to something like "_File", then F is the hotkey for when the window is open. Here's a link that provides more info:

For things like CTRL key combinations, you can bind a view's key commands. This topic provides some information on this subject: This refers to a window's key bindings, but you can do the same with a view and bind it to an action.

May 24, 2013 at 6:10 AM
Note: If memory serves me correctly, then you actually have to open the menu with the keyboard to get a visual indicator for the hotkey. Otherwise, it is shown without an underscore.

May 24, 2013 at 6:03 PM

That explains why, when I tested with the underscore, I didn't see it.... And, of course, MS is also moving away from menus, function keys, etc. which makes maintaining some sort of somewhat similar UI much more difficult. They may be willing to take their end users through drastic changes in UI from one version to another, but many companies can't do that to their customers - at least not that dramatic... :)

Ok, thanks. At least I have a way to get what I need working.

May 24, 2013 at 8:11 PM
I guess they are moving away from menus for some things and on to Ribbons. So we are supporting both of those. I guess Ribbons also have function keys, but nobody every uses them it seems. And then of course there is the whole Metro thing. Sigh. ;-)

FYI: I actually have put it on my list to see if I can automate this whole process further. Maybe I could add another property or two to define access keys and key combinations and then handle that theme specific. Because right now, when you define an access key with the underscore then that works fine in scenarios that use a menu, but it sucks if you were to switch to something like a Metro theme, because then you would actually see the underscore. So it would be nice to handle that better in the framework.

May 24, 2013 at 8:37 PM

It might be nice if there were a character we could use in the menu name that would almost never be used in a menu name (say the ` char) that is used to add an _ char for some themes and is stripped out by others. Or just have some themes automatically strip out any leading underscores... Another option might be to specify a property that can hold the name with the underscore that is used as the menu name by some themes... I am sure you will find an easy solution.

Thanks again!

May 24, 2013 at 8:41 PM
I was more thinking about adding an AccessKey property to the view actions. Really, when you think about it from a logical point of view, combining the access key and the caption is kind of a hack.

May 25, 2013 at 8:18 AM
FYI: Since I was already working on some menu stuff anyway, I took a closer look on this and enhanced this part of the system considerably. You can now (well, in the next build) do this:
var customerAction = new ViewAction("Customer List", execute: (a, o) => Controller.Action("Customer", "Search"))
     AccessKey = 'l',
     ShortcutKey = Key.L,
     ShortcutModifiers = ModifierKeys.Control
 customerAction.Categories.Add(new ViewActionCategory("Data", accessKey: 'd'));
When shown in any theme that uses a standard menu, you would now see a "Data" top level menu in the menu bar with the "d" underlined (assuming you open the menu with the keyboard... so ALT+D will open that Data menu). This is because the category has an access key assigned (d in this case). Furthermore, inside that menu you will then see a "Customer List" item with the "l" being the underlined access key, because that is the access key for the menu item. Alternatively, you can also hit CTRL+L anywhere in that window (assuming there isn't a more local assignment for that key somewhere in a textbox or something like that that fires first) since that is the shortcut key.

So I think this is nice, because it is clean and nicely separated. It also doesn't screw up any of the other themes like Metro or Workplace. (Note: I am working on some support - at least the shortcut keys - in Metro and Workplace also).