I have various checkboxes with Interaction.Triggers and Event Triggers for both Check and Uncheck for each checkbox as shown below. When the checkbox is checked or unchecked I will be catching the CommandParameter value which is different for each checkbox in my ViewModel. I am required to make the Event Triggers as a common code in my XAML which has to work for every different checkbox by catching the CommandParameter value.
<code><framectl:BoundCheckBox UIElementTag="V_NVMCPhaseTripBlockProfileDependent" LabelType="Empty" Grid.Row="3" Grid.Column="17" TabIndex="17" VerticalAlignment="Center" HorizontalAlignment="Center">
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ProfileDependentChecked_Command}" CommandParameter="V_NVMCPhaseTripBlockProfileDependent"/>
<i:EventTrigger EventName="Unchecked">
<i:InvokeCommandAction Command="{Binding ProfileDependentUnChecked_Command}" CommandParameter="V_NVMCPhaseTripBlockProfileDependent"/>
</i:Interaction.Triggers>
</framectl:BoundCheckBox>
<framectl:BoundCheckBox UIElementTag="V_NVMCGroundTripBlockProfileDependent" LabelType="Empty" Grid.Row="4" Grid.Column="17" TabIndex="26" VerticalAlignment="Center" HorizontalAlignment="Center">
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ProfileDependentChecked_Command}" CommandParameter="V_NVMCGroundTripBlockProfileDependent"/>
<i:EventTrigger EventName="Unchecked">
<i:InvokeCommandAction Command="{Binding ProfileDependentUnChecked_Command}" CommandParameter="V_NVMCGroundTripBlockProfileDependent"/>
</i:Interaction.Triggers>
</framectl:BoundCheckBox>
<code><framectl:BoundCheckBox UIElementTag="V_NVMCPhaseTripBlockProfileDependent" LabelType="Empty" Grid.Row="3" Grid.Column="17" TabIndex="17" VerticalAlignment="Center" HorizontalAlignment="Center">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ProfileDependentChecked_Command}" CommandParameter="V_NVMCPhaseTripBlockProfileDependent"/>
</i:EventTrigger>
<i:EventTrigger EventName="Unchecked">
<i:InvokeCommandAction Command="{Binding ProfileDependentUnChecked_Command}" CommandParameter="V_NVMCPhaseTripBlockProfileDependent"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</framectl:BoundCheckBox>
<framectl:BoundCheckBox UIElementTag="V_NVMCGroundTripBlockProfileDependent" LabelType="Empty" Grid.Row="4" Grid.Column="17" TabIndex="26" VerticalAlignment="Center" HorizontalAlignment="Center">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ProfileDependentChecked_Command}" CommandParameter="V_NVMCGroundTripBlockProfileDependent"/>
</i:EventTrigger>
<i:EventTrigger EventName="Unchecked">
<i:InvokeCommandAction Command="{Binding ProfileDependentUnChecked_Command}" CommandParameter="V_NVMCGroundTripBlockProfileDependent"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</framectl:BoundCheckBox>
</code>
<framectl:BoundCheckBox UIElementTag="V_NVMCPhaseTripBlockProfileDependent" LabelType="Empty" Grid.Row="3" Grid.Column="17" TabIndex="17" VerticalAlignment="Center" HorizontalAlignment="Center">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ProfileDependentChecked_Command}" CommandParameter="V_NVMCPhaseTripBlockProfileDependent"/>
</i:EventTrigger>
<i:EventTrigger EventName="Unchecked">
<i:InvokeCommandAction Command="{Binding ProfileDependentUnChecked_Command}" CommandParameter="V_NVMCPhaseTripBlockProfileDependent"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</framectl:BoundCheckBox>
<framectl:BoundCheckBox UIElementTag="V_NVMCGroundTripBlockProfileDependent" LabelType="Empty" Grid.Row="4" Grid.Column="17" TabIndex="26" VerticalAlignment="Center" HorizontalAlignment="Center">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ProfileDependentChecked_Command}" CommandParameter="V_NVMCGroundTripBlockProfileDependent"/>
</i:EventTrigger>
<i:EventTrigger EventName="Unchecked">
<i:InvokeCommandAction Command="{Binding ProfileDependentUnChecked_Command}" CommandParameter="V_NVMCGroundTripBlockProfileDependent"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</framectl:BoundCheckBox>
I have tried the below common code by using a style resource, but that is not firing the command method.
<code><framectl:CCSUserControl.Resources>
<Style x:Key="ProfileDependentCheckedStyle" TargetType="framectl:BoundCheckBox">
<EventTrigger RoutedEvent="CheckBox.Checked">
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ProfileDependentChecked_Command}" CommandParameter="{Binding CommandParameter, RelativeSource={RelativeSource Self}}"/>
</i:Interaction.Triggers>
<EventTrigger RoutedEvent="CheckBox.Unchecked">
<i:EventTrigger EventName="Unchecked">
<i:InvokeCommandAction Command="{Binding ProfileDependentUnChecked_Command}" CommandParameter="{Binding CommandParameter, RelativeSource={RelativeSource Self}}"/>
</i:Interaction.Triggers>
</framectl:CCSUserControl.Resources>
<framectl:BoundCheckBox Style="{StaticResource ProfileDependentCheckedStyle}" UIElementTag="V_NVMCPhaseTripBlockProfileDependent" LabelType="Empty" Grid.Row="2" Grid.Column="17" VerticalAlignment="Center" HorizontalAlignment="Center" TabIndex="8" CommandParameter="V_NVMCPhaseTripBlockProfileDependent"/>
<framectl:BoundCheckBox Style="{StaticResource ProfileDependentCheckedStyle}" UIElementTag="V_NVMCGroundTripBlockProfileDependent" LabelType="Empty" Grid.Row="2" Grid.Column="17" VerticalAlignment="Center" HorizontalAlignment="Center" TabIndex="8" CommandParameter="V_NVMCGroundTripBlockProfileDependent"/>
<code><framectl:CCSUserControl.Resources>
<Style x:Key="ProfileDependentCheckedStyle" TargetType="framectl:BoundCheckBox">
<Style.Triggers>
<EventTrigger RoutedEvent="CheckBox.Checked">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ProfileDependentChecked_Command}" CommandParameter="{Binding CommandParameter, RelativeSource={RelativeSource Self}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</EventTrigger>
<EventTrigger RoutedEvent="CheckBox.Unchecked">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Unchecked">
<i:InvokeCommandAction Command="{Binding ProfileDependentUnChecked_Command}" CommandParameter="{Binding CommandParameter, RelativeSource={RelativeSource Self}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</EventTrigger>
</Style.Triggers>
</Style>
</framectl:CCSUserControl.Resources>
<framectl:BoundCheckBox Style="{StaticResource ProfileDependentCheckedStyle}" UIElementTag="V_NVMCPhaseTripBlockProfileDependent" LabelType="Empty" Grid.Row="2" Grid.Column="17" VerticalAlignment="Center" HorizontalAlignment="Center" TabIndex="8" CommandParameter="V_NVMCPhaseTripBlockProfileDependent"/>
<framectl:BoundCheckBox Style="{StaticResource ProfileDependentCheckedStyle}" UIElementTag="V_NVMCGroundTripBlockProfileDependent" LabelType="Empty" Grid.Row="2" Grid.Column="17" VerticalAlignment="Center" HorizontalAlignment="Center" TabIndex="8" CommandParameter="V_NVMCGroundTripBlockProfileDependent"/>
</code>
<framectl:CCSUserControl.Resources>
<Style x:Key="ProfileDependentCheckedStyle" TargetType="framectl:BoundCheckBox">
<Style.Triggers>
<EventTrigger RoutedEvent="CheckBox.Checked">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ProfileDependentChecked_Command}" CommandParameter="{Binding CommandParameter, RelativeSource={RelativeSource Self}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</EventTrigger>
<EventTrigger RoutedEvent="CheckBox.Unchecked">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Unchecked">
<i:InvokeCommandAction Command="{Binding ProfileDependentUnChecked_Command}" CommandParameter="{Binding CommandParameter, RelativeSource={RelativeSource Self}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</EventTrigger>
</Style.Triggers>
</Style>
</framectl:CCSUserControl.Resources>
<framectl:BoundCheckBox Style="{StaticResource ProfileDependentCheckedStyle}" UIElementTag="V_NVMCPhaseTripBlockProfileDependent" LabelType="Empty" Grid.Row="2" Grid.Column="17" VerticalAlignment="Center" HorizontalAlignment="Center" TabIndex="8" CommandParameter="V_NVMCPhaseTripBlockProfileDependent"/>
<framectl:BoundCheckBox Style="{StaticResource ProfileDependentCheckedStyle}" UIElementTag="V_NVMCGroundTripBlockProfileDependent" LabelType="Empty" Grid.Row="2" Grid.Column="17" VerticalAlignment="Center" HorizontalAlignment="Center" TabIndex="8" CommandParameter="V_NVMCGroundTripBlockProfileDependent"/>