Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I control which nodes are selectable in a WPF TreeView?

Tags:

wpf

treeview

I have a two-level hierarchy displayed in a WPF TreeView, but I only want the child nodes to be selectable - basically the top level nodes are for categorisation but shouldn't be selectable by themselves.

Can I achieve this?

Thanks...

like image 880
Craig Shearer Avatar asked Oct 30 '08 03:10

Craig Shearer


2 Answers

Define styles for each type of items, like Bijington wrote. for non-selectable nodes set the Focusable-Property of the container (TreeViewItem for TreeViews) to false.

like image 141
Paul Avatar answered Nov 15 '22 09:11

Paul


To do so you would need to override the style for treeview. Ideally you will have two types of treeview items one for your top-level nodes (im assuming folders) and another simply for the children, then you should be able to define how each item type in the tree behaves. So create a style for each item type, then for the folder node simply change the trigger for is selected to do nothing.

like image 22
Bijington Avatar answered Nov 15 '22 09:11

Bijington