title: Keybinding a RelayCommand
body: <p>I'm using the <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" rel="noreferrer">RelayCommand</a> in my app. It's great for putting the code in the viewmodel, but how do I bind keystrokes to my command?</p>
  
  <p>RoutedUICommand has its InputGestures property, which makes the command automatically be invoked when I press the keystroke. (As an added bonus, it even makes the keystroke display in the MenuItem.) Unfortunately, there's no reusable interface for RoutedUICommand's extra properties, so I can't make a RelayUICommand that gets the same magic.</p>
  
  <p>I've already tried using InputBindings:</p>
  
  <pre><code>&lt;Window.InputBindings&gt;
      &lt;KeyBinding Key="PageUp" Command="{Binding SelectPreviousLayerCommand}"/&gt;
  &lt;/Window.InputBindings&gt;
  </code></pre>
  
  <p>But that gets me a runtime exception, because KeyBinding.Command isn't a dependency property. (Actually, what it complains about is that KeyBinding isn't even a DependencyObject.) And since my RelayCommand is a property on my ViewModel (as opposed to the static field that RoutedUICommand is designed for), databinding is the only way I know of to reference it from XAML.</p>
  
  <p>How have you guys solved this? What's the best way to bind a keystroke to a RelayCommand?</p>