Sam
Sam

Reputation: 28999

WPF Menu keyboard navigation problems

I've got a WPF program containing a simple Menu.

When The keyboard focus is set into the menu, in Win32 I was able to jump to menu items by typing the first character of the MenuItem name.

In WPF menus this does not work anymore, unless I mark the first character of the menu item using an underscore.

Is this a bug or a feature?

Upvotes: 0

Views: 890

Answers (1)

biju
biju

Reputation: 18000

This is supported in wpf also.It is done by adding an underscore in front of a character. (The ampersand does not work in WPF!).Check the below sample

  <Menu Height="22" Name="menu1" Width="200" Margin="10, 10, 5, 5" HorizontalAlignment="Left" VerticalAlignment="Top" BorderThickness="2">
    <MenuItem Header="_File">

            <MenuItem Header="_Open" IsCheckable="False">
                <MenuItem Header="_One" IsCheckable="True"/>
                <MenuItem Header="_Two" IsCheckable="True"/>
            </MenuItem>

                <MenuItem Header="_Close" IsCheckable="True"/>

                <MenuItem Header="_Save" IsCheckable="True"/>
    </MenuItem>
    </Menu>

The underlined characters show up when you press the Alt key to access the menu. You can then navigate the menu by pressing the underlined characters

Upvotes: 1

Related Questions