Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Word wrap in a datagrid
4 replies. Latest Post by tcook815 on June 29, 2009.
(0)
tcook815
Member
1 points
14 Posts
06-26-2009 3:49 PM |
I have a Silverlight datagrid that completely works and everything. My only question I never could find an answer for. I just want the cells to have word wrap. I created my columns like this
<data:DataGridTextColumn Header="Text of Message" Width="Auto" MinWidth="200" MaxWidth="400" Binding="{Binding Message}" IsReadOnly="False"/>
The text inside of the cells is longer than 400, so it dissappears. Is there a way to get the word wrap? Thank you anyone who can help.
gunjansh...
526 points
88 Posts
06-26-2009 6:40 PM |
DataGridTextColumn currently doesn't support TextWrapping. You could use a TextBlock in a DataGridTemplateColumn instead to achieve this:
<data:DataGridTemplateColumn MinWidth="200" MaxWidth="400" Header="MyLongStringTemplateColumn"> <data:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock TextWrapping="Wrap" Text="{Binding LongString}"/> </DataTemplate> </data:DataGridTemplateColumn.CellTemplate> </data:DataGridTemplateColumn>
Gunjan [MSFT]
06-26-2009 11:06 PM |
Hmm... so I have to go in and turn everything into text boxes... welp, I have a lot of datagrids I have to go and do this to, but if this is the only way to get wrapping, then alright. Thank you for your help!
yifung
Contributor
3257 points
537 Posts
06-28-2009 4:18 PM |
You don't need to convert everything to TextBlocks. You can get to the TextWrapping property by setting an ElementStyle on the column. There's also EditingElementStyle if you need to do something similar with the editing element.
<data:DataGrid x:Name="dataGrid" AutoGenerateColumns="False"> <data:DataGrid.Columns> <data:DataGridTextColumn Binding="{Binding Name}"> <data:DataGridTextColumn.ElementStyle> <Style TargetType="TextBlock"> <Setter Property="TextWrapping" Value="Wrap" /> </Style> </data:DataGridTextColumn.ElementStyle> </data:DataGridTextColumn> </data:DataGrid.Columns> </data:DataGrid>
06-29-2009 10:42 AM |
This works out how I want it to. Thank you everyone for your help!