双击在WPF DataGrid中显示RowDetails双击、WPF、RowDetails、DataGrid

2023-09-04 00:10:36 作者:清酒暖风

目前我的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;
}