private void MainWindow_Loaded(object sender, RoutedEventArgs e) { var window = Window.GetWindow(this); window.KeyDown += HandleKeyPress; }