我有一个 2 层 TreeView,其中充满了一个集合项目,每个项目都有另一个项目集合。
class A
{
public List<B> collection;
}
List<A> treeViewCollection;
我使用 ListCollectionView 使用转换器对这些项目进行排序,如果是集合内的集合,请按照此处的建议进行操作:
如何使用 Xaml 中的 SortDescriptions 对 TreeView 项目进行排序?
我发现的问题是 ListCollectionView 不会对项目进行排序当它们被编辑时,我创建了自己的 ListCollectionView 类来附加到 items 属性通知。我不知道的是,当我检测到某个项目已更改为使用 ListCollectionView 时该怎么办。如果我在 ListCollectionView 上调用 Refresh(),我会丢失 TreeView 上的选择,我在某处看到过使用 Replace 操作引发 CollectionChangedNotification (这对我来说是个好主意),但它对 TreeView 没有影响。
关于如何更新 TreeView 排序而不丢失所有选择和扩展项目的想法吗?
谢谢。
I have a 2 levels TreeView that is filled with a collection items that each one has another collection of items.
class A
{
public List<B> collection;
}
List<A> treeViewCollection;
I'm using a ListCollectionView to sort these items using a converter in the case of the collection inside the collection as recommended here:
How to sort TreeView items using SortDescriptions in Xaml?
The problem that I've found is that the ListCollectionView does not resort the items when they are edited so I've created my own ListCollectionView class to attach to the items property notification. What I don't know is what to do now when I detect that an item has changed to resort the ListCollectionView. If I call Refresh() on the ListCollectionView I lose the selection at the TreeView, I've seen somewhere about raising the CollectionChangedNotification with a Replace action (and that sounds as a good idea to me) but it has no effect on the TreeView.
Any idea on how to update the TreeView sorting without losing all the selections and expanded items?
Thanks.
发布评论