zoukankan      html  css  js  c++  java
  • ListBox绑定MVVM事件问题

    我在使用MVVMLight的时候,给ListBox的ListBoxItem绑定Tap事件 

    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP71"
    <ListBoxItem>
          <StackPanel>
                <i:Interaction.Triggers>
                       <i:EventTrigger EventName="Tap">
                                <cmd:EventToCommand Command="{Binding TapCommand}"></cmd:EventToCommand>
                       </i:EventTrigger>
                 </i:Interaction.Triggers>
                <TextBlock Text="11"></TextBlock>
                <TextBlock Text="222"></TextBlock>
          </StackPanel>
    </ListBoxItem>
    public ICommand TapCommand { get; set; }
    
    TapCommand = new RelayCommand(Tapped);
    
    void Tapped()
    {
                MessageBox.Show("test");
    }

    这样是可以监听到Tap事件的

    但是我现在要使用模板,后台绑定数据

    模板如下

    <ListBox ItemsSource="{Binding Path=UserList}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Tap">
                                    <cmd:EventToCommand Command="{Binding TapCommand}"></cmd:EventToCommand>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                            <TextBlock Text="{Binding id}"></TextBlock>
                            <TextBlock Text="{Binding name}"></TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

    此时Tap页面,监听不到Tap事件,请问应该怎么解决

    代码之美
  • 相关阅读:
    面试汇总
    Windows 环境下的 protoc 安装(转)
    Hbase 元数据一致性检查(转)
    Slow ReadProcessor&amp;Error Slow BlockReceiver错误日志分析(转)
    Hbase CMS GC 调优。
    [技术]排查线上问题
    crontab 误删恢复
    Hbase balancer RSgroup shell 脚本
    Hbase运维手册(1)
    Presto JVM.config
  • 原文地址:https://www.cnblogs.com/betterchaner/p/2521615.html
Copyright © 2011-2022 走看看