我想更改DataGrid选定的行高,而DataGrid中的数据保持不变

问题描述 投票:0回答:1

在选择时,我想更改DataGrid选择的行高。我用了两种方法。 1)我在DataGrid中添加了一个扩展器

<DataGrid x:Name="bookings_dg"  Expander.Expanded="Expander_Expanded"  IsReadOnly="True">
        <DataGrid.RowHeight>30</DataGrid.RowHeight>

这是我的扩展事件

private void Expander_Expanded(object sender, RoutedEventArgs e)
    {
        if (bookings_dg.RowHeight == 100)
        {
            bookings_dg.RowHeight = 20;
        }
        else
        {
            bookings_dg.RowHeight = 100;
        }

    }

它会更改所有行大小而不是特定行大小。

然后我尝试了this它改变了高度,但也扩大了内容。这是我点击之前和之后的数据网格。但我想改变只选择row.before img1After img2的高度

c# datagrid wpf-controls wpfdatagrid wpftoolkit
1个回答
0
投票

您不需要使用后面的代码执行此操作。除非你想让它看起来像放大镜,否则不要使用Scale。

如果您只想在选择该行时增加行高,则可以简单地为行样式添加触发器,以便在选中时增加它们自己的高度。

<DataGrid Name="bookings_dg" IsReadOnly="True">
    <DataGrid.RowStyle>
        <Style TargetType="DataGridRow">
            <Setter Property="Height" Value="30"/>
            <Style.Triggers>   
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Height" Value="50"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </DataGrid.RowStyle>
</DataGrid>
© www.soinside.com 2019 - 2024. All rights reserved.