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

Padu Merloti picture Padu Merloti · Dec 14, 2009 · Viewed 18.6k times · Source

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?

Answer

OrPaz picture OrPaz · Nov 9, 2010

In xaml you could do it as follows :

 <TreeView.ItemContainerStyle>
            <Style TargetType="TreeViewItem">
                <Setter Property="TreeViewItem.IsExpanded" Value="True"/>
            </Style>
 </TreeView.ItemContainerStyle>