Defining MenuItem Shortcuts

后端 未结 6 619
北恋
北恋 2020-11-27 14:02

I need a simple way to set a shortcut for menu items.

But this don´t work with shortcut, just with click:


    <         


        
6条回答
  •  爱一瞬间的悲伤
    2020-11-27 14:59

    H.B. was right... I just wanted to add more precisions.

    Remove the Click event on your MenuItem and associate it with a Command instead.

    1 - Add/create your commands:

    
         
         
    
    

    The commands are refering to the following code:

    private void OpenCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
    {
        Open();//Implementation of open file
    }
    private void SaveAsCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
    {
        SaveAs();//Implementation of saveAs
    }
    

    2 - Associate the commands with the wanted keys:

    
        
        
    
    

    3 - Finally assign the commands with you menu item (InputGestureText is just a decorating text):

    
        
            
            
        
    
    

    That way multiple inputs may be associated to the same command.

提交回复
热议问题