Executing a command on Checkbox.Checked or Unchecked Executing a command on Checkbox.Checked or Unchecked wpf wpf

Executing a command on Checkbox.Checked or Unchecked


<CheckBox Content="CheckBox"          Command="{Binding YourCommand}"          CommandParameter="{Binding IsChecked, RelativeSource={RelativeSource Self}}" />


If you use MVVM, you can use event triggers like this:

<CheckBox IsChecked="{Binding ServiceOrderItemTask.IsCompleted, Mode=TwoWay}" Content="{Binding ServiceOption.Name}">    <i:Interaction.Triggers>          <i:EventTrigger EventName="Checked">                 <i:InvokeCommandAction Command="{Binding DataContext.IsCompletedCheckedCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type t:RadGridView}}}" CommandParameter="{Binding}"/>           </i:EventTrigger>           <i:EventTrigger EventName="Unchecked">                 <i:InvokeCommandAction Command="{Binding DataContext.IsCompletedUncheckedCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type t:RadGridView}}}" CommandParameter="{Binding}"/>           </i:EventTrigger>    </i:Interaction.Triggers>


This will work what you requires -

<CheckBox CommandParameter="{Binding}"          Command="{Binding DataContext.AddRemovePresetAssignmentCommand,          RelativeSource={RelativeSource FindAncestor,                           AncestorType={x:Type UserControl}}}"          Content="{Binding Path=Name}">