Search code examples
c#wpfmenumenuitem

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.


Solution

  • EDIT This is no longer correct. See @Klaus Gütter's answer

    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