Doug
Doug

Reputation: 53

WPF MVVM Checkbox stop Command from firing on Data Bind

I have WPF MVVM application and I am currently trying to use a Checkbox that is bound to a column in a list that it is bound to. I have a EventTriggers set and the command bound to the VM. Everything fires great....Except I do NOT want the events to fire when populated from the list, ONLY when the user checks or unchecks the checkbox. See Code:

    <StackPanel Orientation="Vertical" Background="Transparent" DockPanel.Dock="Right" Margin="2,0" VerticalAlignment="Center">
        <Label Content="Active" />
        <CheckBox x:Name="CbArchiveAoi" VerticalAlignment="Center" HorizontalAlignment="Center" FlowDirection="RightToLeft" IsChecked="{Binding Path=PatientAoi.AoiIsActive}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Checked">
                    <i:InvokeCommandAction Command="{Binding ArchiveAoiCommand, Mode=OneWay}" 
                                       CommandParameter="{Binding ElementName=CbArchiveAoi}"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="Unchecked">
                     <i:InvokeCommandAction Command="{Binding ArchiveAoiCommand, Mode=OneWay}" CommandParameter="{Binding ElementName=CbArchiveAoi}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </CheckBox>
    </StackPanel>

    public ICommand ArchiveAoiCommand
    {
      get { return new RelayCommand<object>(ArchiveAoiExecute, AlwaysTrueCanExecute); }
    }

    private void ArchiveAoiExecute(object obj)
    {
        string dddd = obj.ToString();
    }

Upvotes: 2

Views: 543

Answers (1)

Barracoder
Barracoder

Reputation: 3764

I'd remove the Interaction.Triggers and use the CheckBox.CommandandCommandParameter properties instead.

<CheckBox x:Name="CbArchiveAoi"
          VerticalAlignment="Center"
          <-- snip -->
          Command="{Binding ArchiveAoiCommand, Mode=OneWay}"
          CommandParameter="{Binding ElementName=CbArchiveAoi}" />

Upvotes: 1

Related Questions