0
votes

I am working with WPF TreeView. I have bound the TreeView with it's DataContext property. But whenever I am trying to refresh the TreeView by clearing all the nodes, it's not allowing. I have tried

treeview1.Items.Clear();

but it throws exception.

Please suggest me how can I solve this problem?

1
What do you mean by "it's not allowing"? - Marcinek
it throws exception, can't clear the items - user2979022

1 Answers

1
votes

Because you bound the TreeView to a collection, in your case you need to set the DataContext property to null or an empty collection. Any similar manipulations should be done with your ObservableCollection and not directly with TreeView.