title: Click a WPF button programmatically
body: <p>I am trying to bind an InputGesture to a Button. The XAML of my Button looks like this:</p>
  
  <pre><code>&lt;Button x:Name="StopButton" Content="{Binding StopLabel}" Command="{Binding StopCommand}" IsEnabled="{Binding StartCommand.IsExecuting}" /&gt;
  </code></pre>
  
  <p>The <code>StopCommand</code> is instantiated in the ViewModel:</p>
  
  <pre><code>StopCommand = new Command(_someObject.btnStop_Click);
  </code></pre>
  
  <p>When I manually click the button, <code>btnStop_Click()</code> is executed as expected.</p>
  
  <p>Now, I'd like to add an InputGesture (in the CodeBehind), in order to run <code>btnStop_Click()</code> if "Control + S" is clicked. My CodeBehind looks like this:</p>
  
  <pre><code>public MainControl()
  {
      InitializeComponent();
      try
      {
          _cmd = new RoutedUICommand();
          _cmd.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Control));
          CommandBindings.Add(new CommandBinding(_cmd, Interrupt_event_handler));
      }
      catch (Exception err)
      {
          MessageBox.Show(err.Message);
      }
  }
  
  private void Interrupt_event_handler(object sender, RoutedEventArgs e)
  {
      if (StopButton.IsEnabled)
      {
          StopButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
      }
  }
  </code></pre>
  
  <p>However, when I click "Control + S", nothing happens.</p>