Why do MenuItem headers have underscores before them?

c#, menu, menuitem, wpf

Solution

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

Problem

If you're declaring `MenuItem`s, 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.

Original source