bcm
bcm

Reputation: 5500

How do I expand treeview node by clicking on section header (Silverlight)

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

Answers (1)

Jon Onstott
Jon Onstott

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

Related Questions