Hello,
We are using the new TreeListBox and, while we like it a lot so far, we have the following problem:
We want to sort items in our tree, with custom sort rules. And we want this custom sorting to be applied all the time (even right after renaming a node)
We have our own TreeListBoxItemAdapter override, and our GetChildren override looks like this:
public override IEnumerable GetChildren(TreeListBox ownerControl, object item)
{
var dataExplorerViewModel = item as DataExplorerViewModel;
if (dataExplorerViewModel != null)
return dataExplorerViewModel.SortedChildren;
var treeItem = item as TreeItem;
return treeItem?.SortedChildren;
}
With sortedChildren being:
public IEnumerable SortedChildren
{
get
{
var collectionView = CollectionViewSource.GetDefaultView(Children) as ListCollectionView;
if (collectionView != null)
collectionView.CustomSort = Comparer;
return collectionView;
}
}
It works great but when we rename one item in our explorer, the sorting is not refreshed. To force a new sort of the view, we currently use the following code after each tree item name modification:
var collection = CollectionViewSource.GetDefaultView(Parent.Children);
Dispatcher.CurrentDispatcher.InvokeAsync(() => collection.Refresh());
1. It looks like we are doing the job the control could do.
2. By doing it this way, we are losing the current selection in the tree.
3. This "refresh the default view" solution doesn't look super optimized and we don't want to face issues later in our project, when tree items will be modified frequently by other users (push)
Do you have any advice to handle this use case?
Thanks a lot.
[Modified 7 years ago]