Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do MenuItem headers have underscores before them?

If you're declaring MenuItems, I've always seen their Header properties declared like this:

<MenuItem Header="_Edit">
    <MenuItem Header="_Undo"/>
    <MenuItem Header="_Redo"/>
</MenuItem>

instead of like this:

<MenuItem Header="Edit">
    <MenuItem Header="Undo"/>
    <MenuItem Header="Redo"/>
</MenuItem>

Is there a reason for this or is it just a convention? In the designer it seems to affect nothing whether I have the underscore behind or not.

like image 439
It'sNotALie. Avatar asked Nov 22 '13 17:11

It'sNotALie.


1 Answers

Its to designate the keyboard shortcut.

"_Edit" means that CTRL + E will activate that menu item, whereas

"E_dit" means that CTRL + D will work.

Also, the underscored letter will have an underline when in focus to clue the user in to the keyboard shortcut.

From MSDN

like image 52
crthompson Avatar answered Oct 10 '22 04:10

crthompson