DataGrid event handling in MVVM

岁酱吖の 提交于 2019-12-13 03:39:19

问题


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.

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


回答1:


You can use EventTrigger from System.Windows.Interactivity or MvvmLight

<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>


来源:https://stackoverflow.com/questions/17736154/datagrid-event-handling-in-mvvm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!