title: Binding commands to ToggleButton Checked and Unchecked events
body: <p>I have a ToggleButton in my C# WPF application where I would like to bind one Command to the Checked event and one Command to the Unchecked event.</p>
  
  <p>What I have currently is the following:</p>
  
  <pre><code>&lt;ToggleButton Name="btnOpenPort" Style="{StaticResource myOnOffBtnStyle}" Content="Open Port"
                Checked="btnOpenPort_Checked" Unchecked="btnOpenPort_Unchecked"
                IsChecked="{Binding Path=PortViewModel.PortIsOpen, Mode=OneWay}"
                Canvas.Left="75" Canvas.Top="80" Height="25" Width="100"/&gt;
  </code></pre>
  
  <p>But this is not what I aim to do. Because in this case, I would have to set properties in the code behind for the Checked and Unchecked event.
  Instead, I would like to call a Command (ICommand) in my ViewModel once the Checked or Unchecked event gets fired so that I don't need any code-behind for my toggle button.</p>
  
  <p>Is there a way to bind a command directly for these two events in XAML?
  Similar to the command property of the "standard" button control in WPF?</p>
  
  <p><strong>EDIT</strong>
  This is how it works with regards to @har07 hint:</p>
  
  <p>1: Added references if you dont have it yet:</p>
  
  <pre><code>xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
  xmlns:ei="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
  </code></pre>
  
  <p>2: Implemented Interaction.Triggers for Checked and Unchecked events:</p>
  
  <pre><code>&lt;ToggleButton 
          Name="btnOpenPort" Style="{StaticResource myOnOffBtnStyle}" Content="Open Port"
          IsChecked="{Binding Path=PortViewModel.PortIsOpen, Mode=OneWay}"
          Canvas.Left="75" Canvas.Top="80" Height="25" Width="100"&gt;
          &lt;i:Interaction.Triggers&gt;
              &lt;i:EventTrigger EventName="Checked"&gt;
                  &lt;i:InvokeCommandAction Command="{Binding Path=PortViewModel.OpenPort}"/&gt;
              &lt;/i:EventTrigger&gt;
              &lt;i:EventTrigger EventName="Unchecked"&gt;
                  &lt;i:InvokeCommandAction Command="{Binding Path=PortViewModel.ClosePort}"/&gt;
              &lt;/i:EventTrigger&gt;
          &lt;/i:Interaction.Triggers&gt;
  &lt;/ToggleButton&gt;
  </code></pre>
  
  <p>With this solution, I don't have to change a single line of code in my ViewModel or my code behind.
  I can just call my ICommand as I would do it with a standard button following MVVM pattern.</p>