I'm using a WPF TreeView
with virtualization enabled:
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling"
I would like to select an item which is not visible. E.g. having a tree like this
0
1
3 --
- 3.1
- 3.2
- ...
- 3.500
- ...
- 3.1000
4
5
I would like to select entry 3.500. I've read a lot of other answers already but I got nothing to work. The only thing that's working is this:
VirtualizingPanel panel = VisualHelper.FindVisualChild<VirtualizingPanel>( this.treeView );
panel.BringIndexIntoViewPublic( indexOfItem );
Unfortunately this only seems to work with non hierarchical controls. In my example above the max index is 5 which scrolls to the end of the list (making Item "5" visible).
But what if I want to scroll to an item which is in the child of another item? Like item 3.500? BringIndexIntoViewPublic
is not working anymore.
Calls to someTreeViewItem.BringIntoView()
are also not working - I guess because the items container was not build as its off-screen.
Is there another way to use VirtualizingStackPanel
and programmatically select an item which is not in view?