Reputation: 1325
I have a DataGrid with a DataGridTextColumn, I've set TextBlock.TextWrapping to NoWrap. If I try to display a really really long line, over 10000 characters long the display just cuts of like it's more than TextBlock.MaxWidth. The problem is that it cuts of any following newlines and effectively stops displaying anything else. How can I fix so that either the MaxWidth is longer (I've already set it to max possible) or that it at least displays the newline so that the following lines are displayed.
<DataGrid Grid.Row="0" Name="LogDataGrid" Margin="0,25,0,0" AutoGenerateColumns="False" VirtualizingPanel.ScrollUnit="Pixel" IsReadOnly="True" FontWeight="Normal" CanUserSortColumns="False" IsTabStop="True" HeadersVisibility="Column">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Foreground" Value="{Binding Color}"/>
</Style>
</DataGrid.RowStyle>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="IsTabStop" Value="False"></Setter>
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="DateTime" Binding="{Binding DateTime, StringFormat=\{0:yyyy-MM-dd HH:mm:ss\}}" Width="Auto" />
<DataGridTextColumn Header="Version" Binding="{Binding Version}" Width="60"/>
<DataGridTextColumn Header="Text" Binding="{Binding Text}" Width="{Binding Path=WrapText, Mode=OneWay, Source={x:Static p:Settings.Default}, Converter={StaticResource BooleanDataGridLengthConverter}}">
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="{Binding Path=WrapText, Mode=OneWay, Source={x:Static p:Settings.Default}, Converter={StaticResource BooleanTextWrappingConverter}}" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
How it looks wrapped
When it's not wrapped and the line is REALLY long
Upvotes: 0
Views: 551
Reputation: 406
I prefer to use DataGridTemplateColumn's because you then have more control over the data such as being able to set tool tips. Make sure that the inner textblock has TextWrapping="Wrap" and the width of the template column is the size that you require. Also make sure you don't have a fixed rowheight on the datagrid.
<DataGridTemplateColumn Header="Subject" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Subject}" ToolTip="{Binding Subject}" TextWrapping="Wrap"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Upvotes: 0