This code example shows how to get the position of the scrollbar in a ScrollViewer (with ScrollToVerticalOffset) so that e.g. you can reset the scrollbar to this position if you need to recreate it.
Is there any way to do this for a TreeView control, i.e. get a collection of node indexes which the user has expanded?
The easiest way to do this is to bind TreeViewItem.IsExpanded property to the ViewModel, and then go through model and calculate.
I wrote an example for you. It calculates number of expanded nodes, but you can do whatever you want with expanded guys…
C#:
XAML:
Hope this helps.