在这里回答我自己的问题。
我解决了这个问题,通过将我生成的列上的SortMemberPath设置为RowVM.Cells集合中的索引号,并向我的RowVM添加了SortOnMe属性。
当用户对数据网格进行排序时,它会将包含索引编号(从SortMemberPath获取)的SortDescription添加到PagedCollectionView。我通过使用下面的方法监听PagedCollectionView上的propertychanged事件来监视此情况。它添加了一个新的SortDescription,告诉PagedCollectionView在“SortOnMe”上进行排序,并复制数据以从相关单元格排序到row.SortOnMe。
private bool _currentlySorting;
private void PagedCollectionView_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
var pcv = (PagedCollectionView)sender;
int columnIndex = 0;
if (!_currentlySorting && e.PropertyName == "SortDescriptions" && pcv.SortDescriptions.Count == 1 && int.TryParse(pcv.SortDescriptions[0].PropertyName, out columnIndex)) {
_currentlySorting = true;
pcv.SortDescriptions.Add(new SortDescription("SortOnMe", pcv.SortDescriptions(0).Direction));
foreach (RowViewModel row in pcv.SourceCollection) {
row.SortOnMe = row.Cells(columnIndex).Content;
}
_currentlySorting = false;
}
}
说实话,这是一个相当丑陋的解决方案。但是它很有用,而且我现在花了太多时间在我的墙上猛撞墙。
由于PagedCollectionView是一个密封类(为什么?!),我唯一能想到的做法是创建自己的PagedCollectionView并在那里处理排序。
嗨!感谢您的回复,但我不知道这是如何与我的问题排序silverlight工具包datagrid? – Zissou 2010-07-09 09:32:49