双击datagrid的问题 [英] Issue with doubleclick on datagrid

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

问题描述

我的C#代码中的数据网格上具有以下内容:

I have the following on a datagrid in my C# code:

<DataGrid.InputBindings>  
    <MouseBinding Gesture="LeftDoubleClick" Command="{Binding CmdTransUnitFillerRowDblClick}" />  
</DataGrid.InputBindings>  

它在大多数情况下都有效,除非用户首先选择该行(单击一下)然后尝试两次单击该行。在这种情况下,永远不会触发CmdTransUnitFillerRowDblClick代码进行处理。

It works for the most part except if user first selects the row (single click) and then tries double-clicking the row. In this situation the CmdTransUnitFillerRowDblClick code is never fired for processing.

因此,当行已被选中时,如何使CmdTransUnitFillerRowDblClick在双击上正确触发?

因为有人可能会问:

So, how can I get the CmdTransUnitFillerRowDblClick to fire correctly on a double-click when the row is already selected?
Since someone may ask:

private void ExecutecmdTransUnitFillerRowDblClick(object parameter)  
{
    if (DgTransUnitFillerSelectedItem != null)
        TransUnitFillerDoubleClick(DgTransUnitFillerSelectedItem.CollectionRowId);
}


推荐答案

请参见我对另一个相关问题的回答。问题在于,用户选择行(实际上是单元格)后,数据网格不再具有焦点;用户在数据网格中单击 中的单元格。因此,您必须将焦点更改回数据网格以允许此操作。

See my answer to another related question. The problem is that the datagrid no longer has the focus after the user selects a row (or cell, actually); the cell that the user clicked in the datagrid does. So you have to change the focus back to the datagrid to allow this.

更改:

<DataGrid.InputBindings>  
    <MouseBinding Gesture="LeftDoubleClick" Command="{Binding CmdTransUnitFillerRowDblClick}" />  
</DataGrid.InputBindings>

收件人:

<DataGrid.InputBindings>  
    <MouseBinding Gesture="LeftDoubleClick" Command="{Binding CmdTransUnitFillerRowDblClick}" />  
    <MouseBinding Gesture="LeftClick" Command="{Binding CmdTransUnitFillerRowClick}" />  
</DataGrid.InputBindings>

...并添加:

private void ExecutecmdTransUnitFillerRowClick(object parameter)  
{
    if (DgTransUnitFillerSelectedItem != null)
        The_Name_Of_Your_DataGrid.Focus();
}

这篇关于双击datagrid的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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