<ListBox Grid.Row="1" Grid.Column="1" Style="{StaticResource BasicListBoxStyle}" ItemsSource="{Binding TripAttributeOptions}">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Description}" IsChecked="{Binding ExcludeVal, Mode=TwoWay, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<cmd:EventToCommand PassEventArgsToCommand="True" Command="Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.GroupCheckBoxCheckCommand}"></cmd:EventToCommand>
</i:EventTrigger>
</i:Interaction.Triggers>
</CheckBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
有一个属性绑定到我的Listbox datatemplate的复选框,当该prperty设置为true时,listbox的复选框也被检查,现在我想通过该事件执行命令,但它不会触发。请帮助
答案 0 :(得分:1)
您错过了{
EventToCommand
绑定表达式中的开头Command
:
应该是:
<cmd:EventToCommand PassEventArgsToCommand="True" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.GroupCheckBoxCheckCommand}"></cmd:EventToCommand>
答案 1 :(得分:0)
EventToCommand
对我来说总是觉得不必要的复杂。你为什么要这个命令?
为什么不从ExcludeVal
属性的setter中调用命令的execute方法,该属性绑定到IsChecked
?或者让您的视图模型观看自己的PropertyChanged
事件并查找ExcludeVal
属性更改的时间?