I'm working on a datagrid in WPF and I have encountered a problem.
When adding a multiline string to my DataGridTextColumn, the row is expanded in height so as to fit the entire text. I wish the row height to remain constant at all times, ie only show the first line.
Does anyone know a solution? Seems like a simple enough task, but I havn't been able to find anything of worth on the subject.
Here is my XAML:
<DataGrid Grid.Row="0" AutoGenerateColumns="False" HorizontalAlignment="Stretch" Name="dgPosts" VerticalAlignment="Stretch"
SelectionMode="Single" SelectionUnit="FullRow" ItemsSource="{DynamicResource LogPosts}" CanUserAddRows="False"
IsReadOnly="True" GridLinesVisibility="Vertical" RowHeaderWidth="0" Margin="0,0,0,0"
CanUserReorderColumns="True" CanUserResizeColumns="False" CanUserResizeRows="False" CanUserSortColumns="True" SelectionChanged="dgPosts_SelectionChanged">
<DataGrid.Columns>
<DataGridTextColumn Header="Tidpunkt" Width="120" Binding="{Binding Path=TimeStr}"/>
<DataGridTextColumn Header="Posttyp" Width="55" Binding="{Binding Path=PostTypeStr}" CellStyle="{StaticResource CenterCellStyle}"/>
<DataGridTextColumn Header="Beskrivning" Width="*" Binding="{Binding Path=Text}"/>
</DataGrid.Columns>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Background" Value="{Binding Path=Color}"/>
<Style.Triggers>
<Trigger Property="DataGridRow.IsSelected" Value="True" >
<Setter Property="Background" Value="Black" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="BorderThickness" Value="0"/>
</Style>
</DataGrid.CellStyle>
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
</DataGrid.Resources>
</DataGrid>
Thanks in advance!
You just have to set a Row Height in the DataGrid:
<DataGrid RowHeight="50">
</DataGrid>
And that's it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With