-1

I have a window called MainMenuWindow. I want to show a MessageBox when the user presses F1 on their keyboard, no matter where they are on the window

private void Window_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.F1)
    {
        MessageBox.Show("Help");
    }
}

This is what I have so far.
But I don't know where to reference it or if it's even right. I know how to do it on applications, but cant seem to get it working on .

jAC
  • 5,195
  • 6
  • 40
  • 55
Nicholas Mott
  • 102
  • 3
  • 13

1 Answers1

3

To specify events, you have to add a KeyDown entry to your Windowss code:

<Window xClass="... 
        ...
        ...
        KeyDown="Window_KeyDown">
jAC
  • 5,195
  • 6
  • 40
  • 55
  • If this answer helped you, please [accept it](https://meta.stackexchange.com/a/5235), to mark the question as solved – jAC Jun 03 '17 at 12:21