how can i get shorcut keys

Hi here i'm trying to create a simple menu with simple operations like file open , file close and etc.. how can I get control keys (shortcut keys) for that menu. For example ctrl+s for save , alt+f for open file menu and etc.
Thanx-Nagu


Answer this question

how can i get shorcut keys

  • hz

    Hi here i'm creating a menu like this

    <Menu>

    <MenuItem>

    <MenuItem.Header>_File</MenuItem.Header>

    <MenuItem Click="openMyFile" InputGestureText="Ctrl+O">

    <MenuItem.Header>Open</MenuItem.Header>

    </MenuItem>

    </Menu>

    here "openMyFile" is my method so i want to execute this method when i press Ctrl+O how can i do it I'm trying to do this by using ApplicationCommands.Open but its not working.

    Thanx in help

    Nagu


  • Funkjunky

    As an example, you'd want to do something like this:

    <Window.CommandBindings>
    <CommandBinding Command="ApplicationCommands.Open" Executed="OpenExecuted"/>
    </Window.CommandBindings>
    <Menu>
    <MenuItem Header="_File">
    <MenuItem Header="_New">
    <MenuItem Header="subitem"/>
    </MenuItem>
    <MenuItem Command="ApplicationCommands.Open">
    <MenuItem.Header>_Open</MenuItem.Header>
    </MenuItem>
    <MenuItem Header="_Close" />
    </MenuItem>
    </Menu>

    with code-behind:

    void OpenExecuted(object target, ExecutedRoutedEventArgs e)
    {
    MessageBox.Show("Command invoked.");
    }

    I think the following docs would be helpful to you:

    http://windowssdk.msdn.microsoft.com/en-us/library/ms748845(VS.80).aspx

    http://windowssdk.msdn.microsoft.com/en-us/library/ms753200.aspx

    Thanks,

    Tina



  • new user

    oh thank you

    Bye

    Nagu


  • Dietrich Schaeffler

    Ya i got it here i miss commandBinding to window

    Now its working any way thank your

    Bye

    Nagu


  • how can i get shorcut keys