Multiline text in cells

Dec 3, 2008 at 2:06 PM

How can i make following column:




Controls:DataGridTextColumn Header="Text" Binding="{Binding MessageText}" Width="*" x:Name="textcolumn" />

display the text in the cell in multiple lines?
I am sure it is trivial, but I can't figure it out.

Dec 3, 2008 at 3:38 PM
Edited Dec 3, 2008 at 4:45 PM
I can't see any obvious, trivial way of doing this since there isn't a TextWrapping or other similarly named property on the DataGridTextColumn.

You could try applying a style to the column, either by defining a new style by scratch or by extracting the default style at runtime or using something like Expression Blend if you have it.

You could also try using the DataGridTemplateColumn rather than the DataGridTextColumn, although I'm not sure what the benefits are of using the template column, since any other column type can have a custom template applied anyway. 

I've only just started using the DataGrid myself so I don't really know much about it yet.
Dec 3, 2008 at 5:57 PM
Edited Dec 3, 2008 at 6:00 PM
Maybe something like this?

<Controls:DataGridTextColumn Header="Text" Binding="{Binding MessageText}" Width="*" x:Name="textcolumn">
                        <Style TargetType="TextBlock">
                            <Setter Property="TextWrapping" Value="Wrap"/>
                            <Setter Property="Margin" Value="3"/>
                        <Style TargetType="TextBox">
                            <Setter Property="Foreground" Value="Blue"/>
                            <Setter Property="TextWrapping" Value="Wrap"/>
                            <Setter Property="Margin" Value="3"/>