今天在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>

mvvm 模板中事件没有执行的解决方案的更多相关文章

  1. jquery ajax中事件的执行顺序

    jquery中各个事件执行顺序如下: 1.ajaxStart(全局事件) 2.beforeSend 3.ajaxSend(全局事件) 4.success 5.ajaxSuccess(全局事件) 6.e ...

  2. wamp server mysql数据库中事件不执行的解决办法

    先看看看event 事件是否开启 直接执行下列语句即可, show variables like '%sche%'; 如没开启,则开启. (需要数据库超级权限) set global event_sc ...

  3. ie6下a标签的onclick事件不执行问题解决方案

    <a href="javascript:void(0)" onclick="loadiframe()">点我咯</a> <scri ...

  4. type=file的change事件只能执行一次的解决方案

    最近帮朋友做个项目中遇到了type=file change事件只能执行一次的问题,度娘了一下,发现提供了各种解决方案,所以决定记录一下我的思考方向和最终解决方式. 起初帮朋友做个项目,项目中遇到上传文 ...

  5. C#中WinForm窗体事件的执行次序

    C#中WinForm窗体事件的执行次序如下: 当 Windows Form 应用程序启动时,会以下列顺序引发主要表单的启动事件:        System.Windows.Forms.Control ...

  6. 在TextBox中敲击回车执行ASP.NET后台事件

    1.在TextBox中敲击回车执行ASP.NET后台事件   0.说明 页面中有一个用于搜索的TextBox,希望能在输入内容后直接回车开始搜索,而不是手动去点击它旁边的搜索按钮 但因为该TextBo ...

  7. 解决jquey中当事件嵌套时,内层事件会执行多次的问题

    出现情景:当内层事件需要外层事件触发后产生的一些值得时候 情景复现: <!DOCTYPE html> <html lang="en"> <head&g ...

  8. ThinkPHP+Smarty模板中截取包含中英文混合的字符串乱码的解决方案

    好几天没写博客了,其实有好多需要总结的,因为最近一直在忙着做项目,但是困惑了几天的Smarty模板中截取包含中英文混合的字符串乱码的问题,终于解决了,所以记录下来,需要的朋友看一下: 出现乱码的原因: ...

  9. 在MVVM模式中,按钮Click事件的绑定方法

    在MVVM模式中,我们将Button的方法写到ViewModel中,然后绑定到前端界面.通常的做法是写一个类,继承ICommand接口,然而如果按钮比较多的话,就需要写很多的类,对于后期维护造成很大的 ...

随机推荐

  1. SRM 626 D1L1: FixedDiceGameDiv1,贝叶斯公式,dp

    题目:http://community.topcoder.com/stat?c=problem_statement&pm=13239&rd=15859 用到了概率论中的贝叶斯公式,而贝 ...

  2. springboot @ConfigurationProperties @EnableConfigurationProperties @Bean @ Component

    https://www.cnblogs.com/duanxz/p/4520571.html https://juejin.im/post/5cbeaa26e51d45789024d7e2 1. Bea ...

  3. MongoDB在win7上的安装(精简版)

    1.下载mongdb的zip文件,解压后会发现有bin文件夹,在同层目录下建一个data目录, 2.在data目录下建一个log和db文件夹, 3.在log文件下建一个MongoDB.log 文件 4 ...

  4. WCF基础之配置服务

    在WCF应用编程中配置服务是其主要部分. 配置可以定义和自定义如何向客户端公开服务,包括服务地址,发送和接受消息的传输和编码,以及服务的安全类型. 服务的配置有两种:编码和使用config文件,大多数 ...

  5. Leslie Lamport

    http://lamport.azurewebsites.net/pubs/pubs.html paper

  6. CUDA:零拷贝主机内存

    The easy way to achieve copy/compute overlap!1.Enable Host Mapping* Runtime: cudaSetDeviceFlags() wi ...

  7. Database: coursera assignment 1

    q.1: Find the titles of all movies directed by Steven Spielberg. select title from moviewhere direct ...

  8. webpack笔记1

    1.设置多个入口起点 多用于提取公共类库 a.利用commonChunkPlugin const webpack= require('webpack'); const path = require(' ...

  9. BZOJ 1572 [Usaco2009 Open]工作安排Job:贪心 + 优先队列【先放再更新】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1572 题意: 有n个工作,每个工作有一个截止日期dead[i]和收益pay[i]. 完成一 ...

  10. layer 插件 在子页面关闭自身的方法

    先取到该子页面在父级页面中的name 值 var  index= parent.layer.getFrameIndex(Window.name); 然后用该方法关闭 parent.layer.clos ...