How is it possible to programmatically select an item in a WPF TreeView? The ItemsControl model seems to prevent it.
This is my solution. The others failed for me in various ways. You need to walk the tree from top to bottom, looking for the tree item at each level, expanding and updating the layout along the way.
This function takes a stack of nodes where the first one out of the stack is the top most node, and each subsequent node on the stack is a child of the previous parent. The second argument is the TreeView.
As each item is found, that item is expanded, and the final item is returned, where the caller can select it.
TreeViewItem FindTreeViewItem( Stack
Example of how to call it:
// Build nodeStack here from your data
TreeViewItem treeViewItem = FindTreeViewItem( nodeStack, treeView );
if (treeViewItem != null) {
treeViewItem.IsSelected = true;
treeViewItem.BringIntoView();
}