Detecting the user pressing F10 in WPF

前端 未结 4 1684
迷失自我
迷失自我 2021-01-03 22:40

My WPF application has behaviour triggered by the functions keys (F1-F12).

My code is along these lines:

private void Window_Ke         


        
4条回答
  •  耶瑟儿~
    2021-01-03 23:19

    Answer with DataContext:

    
    
        public partial class BankView : UserControl
        {
            public BankView()
            {
                InitializeComponent();
    
                this.KeyDown += new KeyEventHandler(BankView_KeyDown);
            } 
    
            private void BankView_KeyDown(object sender, KeyEventArgs e)
            {
                try
                {
                    switch (e.Key)
                    {
                        case Key.F4:
                            ((BankViewModel)DataContext).OpenAccount();
                            break;
                    }
                }
                catch (Exception ex)
                {
                    ...
                }
            }
    

提交回复
热议问题