WPF toolkit datagrid cell text wrapping

前端 未结 3 634
忘掉有多难
忘掉有多难 2021-01-18 11:32

My WPF datagrid\'s columns are fixed width, which means long text in the rows are cut off. How can I have the text wrap?

3条回答
  •  粉色の甜心
    2021-01-18 12:09

    If your DataGridTextColumn is being created in the code behind you can set the style and setters this way:

            _dataGridTextColumn.MaxWidth = 550;
            _dataGridTextColumn.ElementStyle = new System.Windows.Style(typeof(TextBlock));
            _dataGridTextColumn.ElementStyle.Setters.Add(new Setter(TextBlock.TextWrappingProperty, TextWrapping.Wrap));
    

    This will cause the text inside the _dataGridTextColumn to wrap as it would inside a TextBlock.

提交回复
热议问题