First letter of underlined menu for shortcut - WPF

3

I'm trying to put a shortcut on my system menu in WPF. In Windows form, just change the text property by placing the "&" before, but in WPF does not use "text" but "content"

Does anyone help me?

<Menu HorizontalAlignment="Left" Height="31" VerticalAlignment="Top" Width="80">
        <MenuItem Header="Cadastro" Height="31" Width="70" Name="ItemCadastro">
            <MenuItem Header="Empresa" HorizontalAlignment="Left" Width="150" Click="MenuItem_Click"/>
        </MenuItem>
</Menu>
    
asked by anonymous 15.04.2015 / 20:24

1 answer

2

To put a keyboard shortcut into a menu, WPF uses the '_' symbol, unlike Windows Forms that uses the '&' symbol before the letter corresponding to the shortcut.

So your menu should be like this, taking into account that the shortcut to enter the Registration item is C, and for the subitem Company is E:

<Menu HorizontalAlignment="Left" Height="31" VerticalAlignment="Top" Width="80">
   <MenuItem Header="_Cadastro" Height="31" Width="70" Name="ItemCadastro">
       <MenuItem Header="_Empresa" HorizontalAlignment="Left" Width="150" Click="MenuItem_Click"/>
   </MenuItem>
</Menu>

Source: MSDN Forums .

    
15.04.2015 / 20:38