mvvm 模板中事件没有执行的解决方案

今天在wpf设计的过程中,用到了listview,数据绑定在模板中进行,其中有个按钮的click事件,一直不执行,很奇怪,找了很久才找到解决办法,原因还是暂时不清除:

<ListView x:Name="LvwClass" ItemsSource="{Binding ClassCollection}" Grid.Column="1">
<ListView.View>
<GridView>
<GridViewColumn Width="60">
<GridViewColumn.Header>
<CheckBox>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<command:EventToCommand Command="{Binding ClassCheckChangedCommand}" CommandParameter="True"></command:EventToCommand>
</i:EventTrigger>
<i:EventTrigger EventName="Unchecked">
<command:EventToCommand Command="{Binding ClassCheckChangedCommand}" CommandParameter="False"></command:EventToCommand>
</i:EventTrigger>
</i:Interaction.Triggers>
</CheckBox>
</GridViewColumn.Header>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Margin="3,0,0,0" IsChecked="True"></CheckBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="60" Header="序号">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource ListViewIndex},RelativeSource={RelativeSource AncestorType={x:Type ListViewItem}, AncestorLevel=1}}" TextWrapping="Wrap"></TextBlock>

</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="60" Header="班级">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding ClassName}" TextWrapping="Wrap"></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="60" Header="操作">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="清除" DataContext="{Binding Id}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<command:EventToCommand Command="{Binding DataContext.ClassItemClearCommand,
RelativeSource={RelativeSource AncestorType=Window,AncestorLevel=1}}"
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ListViewItem,AncestorLevel=1},Path=DataContext}"
></command:EventToCommand>

</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>

</GridView>
</ListView.View>
</ListView>

转载于:https://www.cnblogs.com/sczmzx/p/4643637.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值