I have a WPF application , in which i have a treeview control .
I'd like to collapse all the items by clicking into a button. I tried this:
private void buttonParam_Click(object sender, RoutedEventArgs e)
{
//handling
this.arborescence.IsExpanded = false;
}
but it didn't worked. What are the reasons of this error? How can i change my snippet to do this task?
I think the best way to do this is by looping through all nodes and collapse them 1 by 1.
private void cmdCollapse_Click(object sender, RoutedEventArgs e)
{
foreach (TreeViewItem item in treeview.Items)
CollpaseTreeviewItems(item);
}
void CollapseTreeviewItems(TreeViewItem Item)
{
Item.IsExpanded = false;
foreach (TreeViewItem item in Item.Items)
{
item.IsExpanded = false;
if (item.HasItems)
CollapseTreeviewItems(item);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With