WPF 数据网格选定行单击事件? [英] WPF datagrid selected row clicked event ?

查看:32
本文介绍了WPF 数据网格选定行单击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在双击 WPF DataGrid 的选定行时执行一些代码.我知道数据网格有一个 MouseDoubleClicked 事件,它也有一个行选择事件,但我没有看到双击所选行"的任何事件......

I want to execute some code when a a selected row of the WPF DataGrid is double clicked. I know that the datagrid has a MouseDoubleClicked event and that it also has a row selected event but I don't see any event for "selected row double clicked" ...

您认为有可能以某种方式捕获此事件吗?

Do you think it's possible to capture this event somehow ?

推荐答案

你可以在 ItemContainerStyle(即应用于行的样式)中添加事件处理程序:

you can add the event handler in the ItemContainerStyle (which is the style applied to a row) :

<DataGrid ... >
    <DataGrid.ItemContainerStyle>
        <Style TargetType="DataGridRow">
            <EventSetter Event="MouseDoubleClick" Handler="Row_DoubleClick"/>
        </Style>
    </DataGrid.ItemContainerStyle>
    ...
</DataGrid>

然后,在处理程序中,您可以检查该行是否被选中

Then, in the handler, you can check if the row is selected

private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
{
    // execute some code
}

这篇关于WPF 数据网格选定行单击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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