Unfortunately, as I'm sure you have discovered, is that you can set the treeViewInstance.SelectedItem
property as it's read-only.
From memory, each TreeViewItem
has a IsSelected
property that you can set. You try to listen for expand/collapse on the items and maybe set this property. Without trying this myself I don't know if it is a) a good solution b) if it would even works.
To get the TreeViewItem
that is the container for the item in collection use
treeViewInstance.ItemContainerGenerator.ContainerFromItem(yourDataItem) as TreeViewItem;
Another idea (the way I would do it) is to use a ListBox/ListView and fake the hierarchical view. The create a view model controller and item, wrap your data, and manage this all yourself. If you want more information, please leave a comment and I will dig up a few examples to help.
HTH,
Dennis