WPF MVVM Checkbox stop命令在Data Bind上触发

时间:2014-03-19 14:11:08

标签: c# wpf data-binding mvvm

我有WPF MVVM应用程序,我目前正在尝试使用绑定到绑定到的列表中的列的Checkbox。我有一个EventTriggers设置,并且该命令绑定到VM。一切都很好....除了我不希望从列表中填充事件时,只有当用户选中或取消选中复选框时才会触发事件。见代码:

    <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();
    }

1 个答案:

答案 0 :(得分:1)

我删除了Interaction.Triggers并改为使用CheckBox.CommandCommandParameter属性。

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