MVVM中的DataGrid事件处理 [英] DataGrid event handling in MVVM

查看:377
本文介绍了MVVM中的DataGrid事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGrid,需要处理其事件.我有一个要实现的业务逻辑,需要在ViewModel中进行处理并能够进行单元测试.

I have a DataGrid and need to handle its events. I have a business logic to be implemented which needs to be handled in the ViewModel and able to unit test.

我可以引发事件并在ViewModel中处理它们吗?在这种情况下如何进行单元测试?

Can I raise events and handle them in the ViewModel? In this case how to unit test?

推荐答案

您可以使用 System.Windows.Interactivity或MvvmLight中的EventTrigger

<DataGrid x:Name="myProtokollList">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseDoubleClick">
            <i:InvokeCommandAction  Command="{Binding Path=OpenCommand}" CommandParameter="{Binding ElementName=myProtokollList, Path=SelectedItem.OriginalSatzX}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>

这篇关于MVVM中的DataGrid事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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