【问题标题】:Limit Height of rows for DataGridTextColumn限制 DataGridTextColumn 的行高
【发布时间】:2020-05-11 09:17:02
【问题描述】:

我有一个显示多行的 DataGridTextColumn。通常这些行是单行的,但现在我必须添加一个描述列,其中包含多行文本。这样我的行的高度就会改变。我如何将行的高度限制为单个文本行。由于某种原因,我可以做“MaxWidth”,但不能做“MaxHeight”。

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

【问题讨论】:

    标签: wpf xaml datagrid


    【解决方案1】:

    DataGridTextColumn 没有 MaxHeight 属性,但 DataGridCell 有。所以为该列设置CellStyle

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

    【讨论】:

      【解决方案2】:

      只需使用 RowHeight 属性

       <DataGrid RowHeight="22">
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多