title: Trigger IsPressed property of button with code behind
body: <p>I have a menu with buttons. When a user presses a button it will execute the same method until he releases the button. In other words I start a task on MouseDown and I stop that task on MouseUp.</p>
  
  <p>here is my button</p>
  
  <pre><code>&lt;Button
      x:Name="pushButton"
      Focusable="False"
      Content="{Binding ButtonLabel}"        
      PreviewMouseDown="StartTask"
      PreviewMouseUp = "StopTask"        
   /&gt;
  </code></pre>
  
  <p><strong>I want to be able to press the button with a keyboard shortcut</strong> As a result I have subscribed to the main window event <code>PreviewKeyDown</code> and <code>PreviewKeyUp</code>. Those events get fired correctly and I am able to start the task when the key is down and stop the task when the key is up. <strong>I will like to have the button change its state to as pressed so that the user can see it visually</strong> . How can I change the state of the button to pressed with c# ?</p>
  
  <hr>
  
  <h2>Edit</h2>
  
  <p>I ended up changing its IsPressed value via reflection because the setter is private as:</p>
  
  <pre><code>typeof(Button).GetMethod("set_IsPressed", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(BtnInstance , new object[] { true }); 
  </code></pre>