How is it possible to programmatically select an item in a WPF TreeView
? The ItemsControl
model seems to prevent it.
C# – How to programmatically select an item in a WPF TreeView
citemscontrolnettreeviewwpf
Related Topic
- .net – How to use WPF bindings with RelativeSource
- C# – How to enumerate an enum
- C# – How to get a consistent byte representation of strings in C# without manually specifying an encoding
- C# – When should I use a struct rather than a class in C#
- C# – Data binding to SelectedItem in a WPF Treeview
- C# – Metadata file ‘.dll’ could not be found
- C# – How to exit a WPF application programmatically
Best Answer
For those who are still looking for the right solution to this problem here is the one below. I found this one in the comments to the Code Project article “WPF TreeView Selection” http://www.codeproject.com/KB/WPF/TreeView_SelectionWPF.aspx by DaWanderer. It was posted by Kenrae on Nov 25 2008. This worked great for me. Thanks Kenrae!
Here is his post:
Instead of walking the tree, have your own data object have the IsSelected property (and I recommend the IsExpanded property too). Define a style for the TreeViewItems of the tree using the ItemContainerStyle property on the TreeView that binds those properties from the TreeViewItem to your data objects. Something like this: