我如何处理 WPF DataGrid 上的单元格双击事件,相当于 windows DataGrid 的事件? [英] How do i handle cell double click event on WPF DataGrid, equivalent to windows DataGrid's Events?

查看:25
本文介绍了我如何处理 WPF DataGrid 上的单元格双击事件,相当于 windows DataGrid 的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如您所知,在 windows C# 的 gridview 中,如果我们要处理单元格上的单击/双击事件,则有 CellClick、CellDoubleClick 等事件.

As you know, in windows C#'s gridview, if we want to handle a click/double click event on cell then there are events like CellClick, CellDoubleClick, etc.

所以,我想用 WPF DataGrid 做与 windows gridview 一样的事情.到目前为止,我已经进行了搜索,但答案既不适用也不有用.他们中的一些人说使用 MouseDoubleClick 事件,但在此事件中,我们必须检查每一行以及该行中的项目,因此检查每个单元格的数据很耗时,时间在这里最重要.

So, i wanna do same like as windows gridview with WPF DataGrid. I have searched so far but neither answer is applicable nor useful. Some of them says use the MouseDoubleClick event but, in this event, we have to check for each row as well as item in that row, so it is time consuming to check every cell for data and timing is most important here.

我的 DataGrid 绑定到 DataTable 并且 AutoGeneratedColumn 为 False.如果您的答案是基于 AutoGeneratedColumn=True 那么这是不可能的.甚至,我正在根据数据更改数据网格单元格的样式,因此无法更改 AutoGeneratedColumn 属性.

My DataGrid is bounded to DataTable and AutoGeneratedColumn is False. If your answer is based on AutoGeneratedColumn=True then it is not possible. Even, i 'm changing the styles of datagrid cell according to data, so there is no way to change AutoGeneratedColumn property.

单元格单击/双击事件应该与 Windows 网格的事件一样快.如果可以,请告诉我如何做,如果不能,那么有什么替代方法?

A Cell Clicking/Double Clicking event should be as faster as windows grid's event. If it is possible then tell me how, and if not, then what is the alternative to do it?

请帮帮我.....

非常感谢....

推荐答案

我知道这对派对来说可能有点晚了,但这可能对其他人有用.

I know this may be a little late to the party, but this might be useful to someone else down the road.

在您的 MyView.xaml 中:

In your MyView.xaml:

<DataGrid x:Name="MyDataGrid" ...>
    <DataGrid.Resources>
        <Style TargetType="{x:Type DataGridCell}">
            <EventSetter Event="MouseDoubleClick" Handler="DataGridCell_MouseDoubleClick"/>
        </Style>
    </DataGrid.Resources>

    <!-- TODO: The rest of your DataGrid -->
</DataGrid>

在您的 MyView.xaml.cs 中:

In your MyView.xaml.cs:

private void DataGridCell_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    var dataGridCellTarget = (DataGridCell)sender;
    // TODO: Your logic here
}

这篇关于我如何处理 WPF DataGrid 上的单元格双击事件,相当于 windows DataGrid 的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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