zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    hadoop-2.7.3安装kafka_2.11-2.1.0
    HBase数据快速导入之ImportTsv&Bulkload
    hbase shell 基本操作
    SQLplus命令中删除键和翻页键不能用的问题
    SQL*Loader 的使用sqlldr和sqluldr2方法详解
    python连接oracle导出数据文件
    python零碎知识点一
    用Python输出一个Fibonacci数列
    问题总结——window平台下gruntower安装后无法运行的问题
    JavaScript学习笔记——浅拷贝、深拷贝
  • 原文地址:https://www.cnblogs.com/sczmzx/p/4643637.html
Copyright © 2011-2022 走看看