This project is read-only.

Scroll to display newly added tree items


This is more of a feature request than an issue.

I think it would be nice if it scrolls automatically to display any newly added tree items. Scroll up or down just enough to get the new item fully in the view.

If there is a way to do this from outside the tree I could do that instead.

Thanks again for your efforts! :)



nkast wrote Oct 23, 2014 at 3:17 PM

I am using this code to do so when an item is selected:
TreeViewExItem tvei = treeView.GetTreeViewItemFor((object)treeItem);
if (tvei != null) tvei.BringIntoView(new Rect(1, 1, 1, 1));
If i remember correctly the functions GetTreeViewItemFor() & BringIntoView were not public.

I agree with Simon, The view should scroll automatically to show new items and selected items (when selected/added from the ViewModel).

In general it would be better if we get a clean seperation between Input and UI changes.
For example: If someone click on an item, that shouldn't cause any UI changes down the line. It should only change the observable SelectedItems. Other parts of the control would react to the change.
The control would initiallise SelectedItems with it's own at the beggining or use a shadow collection when SelectedItems is null.

nkast wrote Oct 23, 2014 at 5:48 PM

I send patch 16913 that BringIntoView selected items.

Doing the same thing for new items is a bit tricky, by the time we get a ChangeNotify event for the item there is no corresponding visual TreeItemEx. The TreeItemEx is created in the MessureOveride() overload of VirtualizingTreePanel but it's not attacked to the visual tree yet so a call to BringIntoView has unspecified results.

thekapptin wrote Oct 23, 2014 at 7:12 PM

That sounds like a good workaround nkast.
I could easily select & unselect any newly added items to bring them into the view.

nkast wrote Oct 23, 2014 at 11:39 PM

@thekapptin Try patch 16914.
var newNode = new Node { Name = "elementNew" };
Maybe autoscroll to new items is not a good idea anyway, especially during initialization when the user might add millions of items.
This still could have a few issues, haven't tested it what happens if you add/select an item that's inside a collapsed item. We probably need to expand all ancestor items.

wrote Oct 29, 2014 at 11:35 AM