I am binding an ObservableCollection to a Datagrid. Everything is working besides this row height issue I've been fighting for a while now.
The Issue is the row heights are storing the largest cell's height and not changing from that.
If I have a collection of 5 objects. In ASC order,Row 1 height is 100 and row 5 height is 20. If I resort the same column to DESC then row 1 height is now 100 and row 5 height is 100 as well.
I've tried wrapping the Datagrid in a Scrollviewer and changed DataGridTextColumn to DataGridTemplateColumn with a vertical aligned text box. Silverlight doesn't have ViewCollectionSource so I couldn't try that one.
How can I get it to recalculate the height after a sort?
XAML
SelectedItem="{Binding SelectedComment, Mode=TwoWay}"
VerticalAlignment="Top"
Width="1000"
Height="Auto"
>
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn Header ="Comment" Width="4*" IsReadOnly="True" SortMemberPath="Commentstr" CanUserSort="True">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Commentstr}" TextWrapping="Wrap" VerticalAlignment="Top"></TextBlock>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
Code-Behind
private ObservableCollection<Comment> commentCollection = new ObservableCollection<Comment>();
public ObservableCollection<Comment> CommentCollection
{
get { return commentCollection; }
set
{
commentCollection = value;
}
}
public Main()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(CustomScreenTemplate_Loaded);
CommentGrid.ItemsSource = CommentCollection;
}