Christian
Christian

Reputation: 1194

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?

Upvotes: 0

Views: 564

Answers (1)

Daniel
Daniel

Reputation: 75

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.

Upvotes: 2

Related Questions