【问题标题】:I want to change DataGrid selected row height While data in the DataGrid remains unchanged我想更改 DataGrid 选定的行高而 DataGrid 中的数据保持不变
【发布时间】:2019-01-26 07:28:42
【问题描述】:

在选择时,我想更改 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 它改变了高度但也扩大了其中的内容。 这是我点击前后的数据网格。但我想只改变选定行的高度。before img1After img2

【问题讨论】:

    标签: c# datagrid wpf-controls wpfdatagrid wpftoolkit


    【解决方案1】:

    您无需在代码后面执行此操作。除非您希望它看起来像放大镜,否则不要使用 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>
    

    【讨论】:

    • 非常感谢您的回复,其中存在一个问题,它只增加行高而不增加其中的单元格高度。
    • 对我有用。如果我在单元格上设置背景颜色或边框,它将填充整行。文本保持与左上角位置对齐,但这是因为在 DataGridCell 内部使用了 TextBlock 来显示它。是这个意思吗?
    • 实际上我想增加放置在行内的 texBlock 的高度。
    猜你喜欢
    • 2015-12-26
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    • 2013-04-25
    • 2014-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多