C# WPF MVVM复选框停止在数据绑定时触发命令
我有一个WPF MVVM应用程序,我目前正在尝试使用一个复选框,该复选框绑定到它绑定到的列表中的一列。我设置了一个EventTriggers,并将命令绑定到VM。一切都很好…除了我不希望在从列表填充时触发事件,仅当用户选中或取消选中复选框时。见代码:C# WPF MVVM复选框停止在数据绑定时触发命令,c#,wpf,data-binding,mvvm,C#,Wpf,Data Binding,Mvvm,我有一个WPF MVVM应用程序,我目前正在尝试使用一个复选框,该复选框绑定到它绑定到的列表中的一列。我设置了一个EventTriggers,并将命令绑定到VM。一切都很好…除了我不希望在从列表填充时触发事件,仅当用户选中或取消选中复选框时。见代码: <StackPanel Orientation="Vertical" Background="Transparent" DockPanel.Dock="Right" Margin="2,0" VerticalAlignment="Ce
<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();
}
公共ICommand ArchiveAOI命令
{
获取{returnnewrelaycommand(ArchiveAoiExecute,AlwaysTrueCanExecute);}
}
私有void ArchiveAoiExecute(对象obj)
{
字符串dddd=obj.ToString();
}
我将删除交互。触发器并使用复选框。命令
和命令参数
属性
<CheckBox x:Name="CbArchiveAoi"
VerticalAlignment="Center"
<-- snip -->
Command="{Binding ArchiveAoiCommand, Mode=OneWay}"
CommandParameter="{Binding ElementName=CbArchiveAoi}" />
如何从列表中填充它?在上面的代码中,您可以看到对IsChecked属性所做的绑定。PatientAoi是虚拟机中的一个对象。马克…谢谢…我想我已经试过了。显然不是。再次感谢!