How get a WPF Datagrid with cells that wrap text instead of truncating it? How get a WPF Datagrid with cells that wrap text instead of truncating it? wpf wpf

How get a WPF Datagrid with cells that wrap text instead of truncating it?


Thanks for your help @H.B., this did the trick for me (alignment is optional):

<DataGrid.Columns>                   <DataGridTextColumn Header="Wrapped & centered" Binding="{Binding field}">        <DataGridTextColumn.ElementStyle>             <Style>                                             <Setter Property="TextBlock.TextWrapping" Value="Wrap" />                 <Setter Property="TextBlock.TextAlignment" Value="Center"/>             </Style>         </DataGridTextColumn.ElementStyle>    </DataGridTextColumn></DataGrid.Columns>


I made something similar to D.Rosados solution. Mine is however reusable if you have more columns that needs wrapping.

<UserControl.Resources>    <Style TargetType="{x:Type TextBlock}" x:Key="WrapText">        <Setter Property="TextWrapping" Value="Wrap"/>    </Style></UserControl.Resources><DataGrid.Columns>    <DataGridTextColumn IsReadOnly="False" Header="Address"      Binding="{Binding Address}" ElementStyle="{StaticResource WrapText}" Width="150"/></DataGrid.Columns>


You could try to template the cells with a TextBlock which has text-wrapping enabled.