CheckBox [Inside ListBox ItemTemplate] Checked 事件未触发 [英] CheckBox [Inside ListBox ItemTemplate] Checked Event is not triggering

查看:29
本文介绍了CheckBox [Inside ListBox ItemTemplate] Checked 事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的xaml

    <ListBox x:Name="HistoryList"          
                     ItemsSource="{Binding HistoryCollection}" 
                       >
        <ListBox.ItemTemplate >
            </DataTemplate>                 
                    <CheckBox x:Name="UpCheckBox"   Height="50" Width="50" >
                        <interactivity:Interaction.Triggers>
                            <interactivity:EventTrigger EventName="Checked">
                                <interactivity:InvokeCommandAction Command="{Binding UpCheckedCommad}" CommandParameter="{Binding ElementName=UpCheckBox}"></interactivity:InvokeCommandAction>
                            </interactivity:EventTrigger>
                        </interactivity:Interaction.Triggers>
                    </CheckBox>                 
            </DataTemplate>
        </ListBox.ItemTemplate >
    </ListBox >

ViewModel 中我使用了 GalasoftMVVM 命令绑定

    public ICommand UpCheckedCommad
    {
        get { return new RelayCommand<Object>(x => { PerformUpforTracks(x); }); }
    }

    void PerformUpforTracks(object x)
    {
        //TODO 
    }

我在 ListBox ItemTemplate 中使用了 CheckBox.但是我没有得到 CheckBoxChecked 事件ViewModel .
我想从我的 ViewModel 中获取 Checked 事件.
有没有人知道如何解决这个问题?

I used a CheckBox inside a ListBox ItemTemplate.But am not getting the Checked Event of CheckBox in the ViewModel .
I wanted to get the Checked Event from my ViewModel.
Can anyone have any idea to resolve this issue?

推荐答案

我是通过这种方式绑定Command得到的

I got it By Binding Command by this way

Command="{Binding Path=DataContext.UpCheckedCommad,
          ElementName=HistoryList}" 

这篇关于CheckBox [Inside ListBox ItemTemplate] Checked 事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆