简体   繁体   中英

WPF treeview items clear

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM