简体   繁体   中英

WPF C# Show Window on Keypress

I want to show a Window only when I press a specific key combination. At start the Window is not visible and has no focus. When I press for example three keys together the window shows up.

Is this even possible in WPF? And how?

If your application is started, you must have the focus in some window. In that window you can add a method that handle a Keyup or KeyDown event. In that event you can control the keys pressed and open the new window. For example:

Private Sub dataGrid_PreviewKeyUp(sender As Object, e As KeyEventArgs)
    If e.Key = Key.Enter Then
        Dim newWindow As CustomWindow = New CustomWindow()
        newWindow.ShowDialog()
    End If
End Sub

Hope it help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM