Reputation: 5500
How do I expand the node by clicking on the item text?
Purpose is to make it easier to expand or close a node, apart from depending on the Expander arrow button.
Upvotes: 1
Views: 1210
Reputation: 13727
This seems to work. This toggles the item expanded/collapsed, but you could do item.IsExpanded = true;
instead if you like.
TreeViewItem item = (TreeViewItem)treeView.ItemContainerGenerator.ContainerFromItem(treeView.SelectedItem);
item.IsExpanded = !item.IsExpanded;
You can fire this code in the mouse-button-up event handler of your label. If you put it in the mouse-down event handler, the tree view item won't have been selected yet.
Upvotes: 1