Search code examples
wpfxamldatagrid

Limit Height of rows for DataGridTextColumn


I have a DataGridTextColumn which shows several rows. Normally those rows are oneliner, but now i had to add a description Column which contains more Text in several lines. That way the height of my rows changes. How can i limit the height of the row to be a single text line. I can do "MaxWidth" but not "MaxHeight" for some reason.

<DataGrid.Columns>
<DataGridTextColumn Header="Header_Txt" Binding="{Binding Result.Header_Txt}" MaxWidth="200"/>
</DataGrid.Columns>

Solution

  • DataGridTextColumn has not a MaxHeight property, but the DataGridCell has. So set the CellStyle for the column:

    <DataGridTextColumn ...>
        <DataGridTextColumn.CellStyle>
            <Style TargetType="DataGridCell">
                <Setter Property="MaxHeight" Value="22"/>
            </Style>
        </DataGridTextColumn.CellStyle>
    </DataGridTextColumn>