2014-03-19 60 views
1

我有WPF MVVM應用程序,我目前正在嘗試使用複選框綁定到它綁定到列表中的列。我有一個EventTriggers集並綁定到VM的命令。除非我不希望事件從列表中填充,只有在用戶選中或取消選中複選框時纔會觸發事件。見代碼:WPF MVVM複選框停止命令從數據綁定發射

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

如何從列表中填充它? – cederlof

+0

在上面的代碼中,您可以看到對IsChecked屬性執行的綁定。 PatientAoi是VM中的一個對象。 – Doug

回答

1

我刪除Interaction.Triggers和使用CheckBox.CommandCommandParameter屬性,而不是。

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

馬克......謝謝......以爲我曾嘗試過。顯然不是。再次感謝! – Doug