Assign Short Cut Key to a button in WPF

前端 未结 5 903
梦毁少年i
梦毁少年i 2020-12-03 05:15

How to assign short-cut key to a button in WPF?

Googling gave me the answer as to append _ instead of \'&\' in standard Winforms.

So after I have done a

5条回答
  •  我在风中等你
    2020-12-03 05:34

    Solution for key binding (+ button binding) with own commands:

    The body of XAML file:

    
        
        
    
    
    
        
        
    
    
    
        
        
    
    
    
        

    and .CS file:

    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }
    
        public void FirstMethod(Object sender, ExecutedRoutedEventArgs e)
        {
            // btn1
        }
    
        public void SecondMethod(Object sender, ExecutedRoutedEventArgs e)
        {
            // btn2
        }
    }
    

提交回复
热议问题