今天在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. Windows 驱动入门(二)代码结构

    windows驱动程序基础.转载标明出处:http://blog.csdn.net/ikerpeng/article/details/38777641 windows驱动程序结构: 我想说的是wind ...

  2. npm 全局配置放在c盘/用户/当前用户/目录下

    prefix=D:\Users\Ed\AppData\Roaming\nodejs\npm-globalcache=D:\Users\Ed\AppData\Roaming\npm-cacheregis ...

  3. 最近两周我们接触到的两种线上抓娃娃机的技术实现方案(一种RTSP/一种RTMP)

    线上抓娃娃机需求 最近线上抓娃娃机的项目火爆了,陆陆续续几十款线上抓娃娃机上架,还有一大波正在开发上线中,各大视频云提供商都在蹭热度发布自己的线上抓娃娃机方案,综合了一下,目前线上抓娃娃机的视频需求无 ...

  4. hdu 4667 Building Fence < 计算几何模板>

    //大白p263 #include <cmath> #include <cstdio> #include <cstring> #include <string ...

  5. pip3 Fatal error in launcher: Unable to create process using '"' [转]

    在新环境上安装python的时候又再次遇到了这个情况,这次留意了一下,发现原来的文章有错误的地方,所以来更新一下,应该能解决大部分的问题. 环境是win8,原来只安装了python2.7.后来因为要用 ...

  6. cocos2d-js添加百度appx的插屏广告(通过jsb反射机制)

    本来一直用的anysdk接入广告,结果从前几天开始,百度商店的审核总是通不过,结果一问才知道:要上传到百度商店就必须要用百度的appx(真的是各种坑,我们这些个人开发者迟早要被你们大公司玩死),没办法 ...

  7. 【网络与系统安全】利用burpsuite进行重放攻击

    重放攻击的定义 所谓重放攻击就是攻击者发送一个目的主机已接收过的包,来达到欺骗系统的目的,主要用于身份认证过程. 原理 重放攻击的基本原理就是把以前窃听到的数据原封不动地重新发送给接收方.如果攻击者知 ...

  8. 【Java线程】锁机制:synchronized、Lock、Condition(转)

    原文地址 1.synchronized 把代码块声明为 synchronized,有两个重要后果,通常是指该代码具有 原子性(atomicity)和 可见性(visibility). 1.1 原子性 ...

  9. Maven简介(六)——Dependency

    7      Dependency介绍 http://elim.iteye.com/category/269897 7.1     依赖的传递性 当项目A依赖于B,而B又依赖于C的时候,自然的A会依赖 ...

  10. bind、call、apply的区别与实现原理

    1.简单说一下bind.call.apply的区别 三者都是用于改变函数体内this的指向,但是bind与apply和call的最大的区别是:bind不会立即调用,而是返回一个新函数,称为绑定函数,其 ...