<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>
有一个属性绑定到我的列表框DataTemplate中的复选框,当prperty设置为true,列表框的复选框也得到遏制,现在我想通过事件执行命令但它不会触发。请帮忙火灾使用WPF MVVM控件出现在DataTemplate中的ListBox的事件
其实我不能这样做,因为我的ExcudeVal属性是POCO实体的属性。所以我不能做这件事。 –
我希望你的ViewModel的任何属性在Binding表达式中用来至少引发OnPropertyChanged事件。如果没有,那么我会将该属性包装在ViewModel中的一个新属性中,该属性会引发事件。 – CoderDennis
然后,将您的POCO包装到一个简单的ViewModel类中,比如TripAttributeOptionViewModel,这可能是一个好主意。或者,你可以尝试CommandReference类(只是谷歌它)。我用它来做这样的事情。它允许您通过StaticResource而不是混乱的相对源绑定来引用数据模板之外的命令(如在窗口的数据上下文中)。 –