【发布时间】:2017-03-11 13:51:17
【问题描述】:
我将 ObservableCollection 绑定到 Datagrid。除了我一直在努力的这个行高问题之外,一切都在工作。
问题是行高存储了最大单元格的高度,并且不会改变。
如果我有 5 个对象的集合。在 ASC 顺序中,第 1 行高度为 100,第 5 行高度为 20。如果我将同一列使用 DESC,则第 1 行高度现在为 100,第 5 行高度也为 100。
我尝试将 Datagrid 包装在 Scrollviewer 中,并将 DataGridTextColumn 更改为 DataGridTemplateColumn,并带有垂直对齐的文本框。 Silverlight 没有 ViewCollectionSource,所以我无法尝试。
如何让它在排序后重新计算高度?
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>
代码隐藏
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;
}
【问题讨论】:
标签: silverlight datagrid