Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expand all nodes of a WPF treeview in code behind?

I might be suffering of Monday's dumbness, but I can't find a nice way of expanding all treeview nodes after I've added them in code behind (something like treeView.ExpandAll()).

Any quick help?

like image 995
Padu Merloti Avatar asked Dec 14 '09 18:12

Padu Merloti


People also ask

How to expand TreeView in WPF?

To expand a treeview item you need to set the IsExpanded attribute to True. Conversely, in order to collapse an item you should set the IsExpanded attribute to False. The default value of the IsExpanded property is False.

How do you expand node in TreeView?

Use TreeNode. Expand() on every node from the root to the leaf you wanted to be expanded, using Expand on the leaf node or the node you want to expand make only the node itself to show its subchildren.

How do you expand all Treeviews?

You can expand all nodes in the TreeView by default by setting up an ItemContainerStyle for the TreeView and specifying that you want each TreeViewItem expanded.

What is TreeView in WPF?

The TreeView control provides a way to display information in a hierarchical structure by using collapsible nodes. This topic introduces the TreeView and TreeViewItem controls, and provides simple examples of their use.


1 Answers

In xaml you could do it as follows :

 <TreeView.ItemContainerStyle>
            <Style TargetType="TreeViewItem">
                <Setter Property="TreeViewItem.IsExpanded" Value="True"/>
            </Style>
 </TreeView.ItemContainerStyle>
like image 175
OrPaz Avatar answered Oct 03 '22 04:10

OrPaz