WPF Press any button to continue to next page

时间:2019-01-18 18:57:25

标签: c# wpf xaml controls

Got a simple 3 page program, but would like to make a welcome screen that users have to press a button to move to the next page (and start the workflow). Users will mostly be using a barcode scanner (captures string & hits enter), so I'm trying to avoid buttons that need to be clicked with a mouse. The setup is basically one MainWindow with a DockPanel in it with a Frame in it. Pages get loaded to the frame on events(the enter being hit on a textbox). Pages have Grids in them with the standard controls. I've got the frame in the window navigating to the welcome page, but can't seem to capture a keypress. What would set I the event on? The Window, the frame, the dockpanel, the page, the grid? Also, is there a way to specify "any key or click" event, maybe listen for any input action? I've tried experimenting and looking at documentation but I can't seem to get it.

2 个答案:

答案 0 :(得分:0)

我创建了一个带有框架的空WPF应用,并且能够捕获按键事件。应用启动后,我将专注于框架。页面加载后或工作流程重新开始时,您可以执行相同的操作。

onCreate

答案 1 :(得分:0)

将此添加到您的设计器中:

this.myForm.KeyDown += new System.Windows.Forms.KeyEventHandler(this.myForm_KeyDown);

并将其添加到表单的代码中

private void myForm_KeyDown(object sender, KeyPressEventArgs e)
{
     if(KeysDown().Any()) 
     {
         currentForm.Hide();
         nextForm,Show();
     }
}