【发布时间】:2014-03-19 14:11:08
【问题描述】:
我有 WPF MVVM 应用程序,我目前正在尝试使用一个复选框,该复选框绑定到它所绑定的列表中的列。我有一个 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();
}
【问题讨论】:
-
如何从列表中填充它?
-
在上面的代码中,您可以看到对 IsChecked 属性所做的绑定。 PatientAoi 是 VM 中的一个对象。
标签: c# wpf data-binding mvvm