I am trying to create a simple DataGrid in Silverlight 4 Beta but cannot seem to figure out how to get my Note
column to wordwrap.
The table represents notes made on an order, so they will be of variable length. i want the 'Note' cell to expand vertically to fit the contents.
I've found numerous similar questions but no answer. Is there something new in Silverlight 4 that will address this?
<data:DataGrid AutoGenerateColumns="False" Name="dataGrid1" IsReadOnly="True">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="Date" Binding="{Binding Date}" />
<data:DataGridTextColumn Header="User" Binding="{Binding User}" />
<data:DataGridTextColumn Header="Note" Binding="{Binding Note}" />
</data:DataGrid.Columns>
</data:DataGrid>
Use a DataGridTemplateColumn instead of a text column. Have a TextBlock in there with it's TextWrapping set to true:
<data:DataGrid x:Name="LayoutRoot" AutoGenerateColumns="False" IsReadOnly="True" RowDetailsVisibilityMode="Visible" >
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="Date" Binding="{Binding Date}" />
<data:DataGridTextColumn Header="User" Binding="{Binding User}" />
<data:DataGridTemplateColumn Header="Note" Width="100">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding Note}" />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
</data:DataGrid.Columns>
</data:DataGrid>
I use ElementStyle to set the wrap text,and it works all right. Happy coding!
<Style x:Key="DataGridTextColumnStyle" TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
<data:DataGridTextColumn Binding="{Binding DESC}"
Header="Short Description"
HeaderStyle="{StaticResource DataGridHeaderStyle}"
ElementStyle="{StaticResource DataGridTextColumnStyle}" >
</data:DataGridTextColumn>
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