在 WPF DataGrid 中双击显示 RowDetails [英] Show RowDetails on double-click in WPF DataGrid

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

问题描述

目前,当我单击一行时,我的 DataGrid 会显示 RowDetails.但我只想在双击时显示 RowDetails.

At the moment my DataGrid shows the RowDetails when i click a row. But I want to show the RowDetails only on Double-click.

有解决这个问题的想法吗?

Any ideas for solving this problem?

谢谢!

推荐答案

例如

<DataGrid RowDetailsVisibilityMode="Collapsed">
    <DataGrid.RowStyle>
        <Style TargetType="{x:Type DataGridRow}">
            <EventSetter Event="MouseDoubleClick" Handler="RowDoubleClick"/>
        </Style>
    </DataGrid.RowStyle>
</DataGrid>

private void RowDoubleClick(object sender, RoutedEventArgs e)
{
    var row = (DataGridRow)sender;
    row.DetailsVisibility = row.DetailsVisibility == Visibility.Collapsed ?
        Visibility.Visible : Visibility.Collapsed;
}

这篇关于在 WPF DataGrid 中双击显示 RowDetails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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