title: How can I handle a shortcut key in every WPF window?
body: <p>I want to open the help file to a page based on some custom logic. How can I handle the user pressing F1 on all of my windows (main window and modal dialogs) ?</p>
  
  <p>I know how to handle F1 in a single window, but can this be done globally, so I don't have to add the same code to all of my windows ?</p>
  
  <p>Below is the test with which I've tried out that F1 does not work on the child window.</p>
  
  <p>Window1.xaml:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication2.Window1"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
      &lt;Window.CommandBindings&gt;
          &lt;CommandBinding Command="ApplicationCommands.Help"
                          Executed="CommandBinding_Executed"/&gt;
      &lt;/Window.CommandBindings&gt;
      &lt;Grid&gt;
          &lt;Button Content="Open a new window"
                  Click="Button_Click"/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Window1.xaml.cs:</p>
  
  <pre><code>using System.Windows;
  using System.Windows.Input;
  
  namespace WpfApplication2
  {
      partial class Window1 : Window
      {
          public Window1()
          {
              InitializeComponent();
          }
  
          void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
          {
              MessageBox.Show("Help");
          }
  
          void Button_Click(object sender, RoutedEventArgs e)
          {
              new Window().ShowDialog();
          }
      }
  }
  </code></pre>