I have a WPF MainWindow and try to react to a certain key combination (CTRL + F4). I registered the following methods for testing purposes:
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
Log.AsInfo("PreviewKeyDown");
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
Log.AsInfo("KeyDown");
}
private void Window_KeyUp(object sender, KeyEventArgs e)
{
Log.AsInfo("KeyUp");
}
private void Window_PreviewKeyUp(object sender, KeyEventArgs e)
{
Log.AsInfo("PreviewKeyUp");
}
Crazy thing is, those methods are only triggered after I interact with the application for the first time:
How it does not work:
- I start the application
- I enter CTRL + F4 on the keyboard
- Nothing happens
How it works:
- I start the application
- I click on a random menu item with no functionality
- I enter CTRL + F4 on the keyboard
- Everything works, log messages are written
Any ideas? I am not able to even debug the situation, because none of the handler methods is called in the first place. I even tried this.Focus()
in the MainWindow constructor, but this did not help either.