C# – WPF MVVM – Refresh Treeview

cdata-bindingmvvmnetwpf

I have created a Treeview in WPF MVVM (Project is using MVVM Light).

When I add a data to a DataTemplate of the Treeview, I want to reload the entire treeview. For this I am sending a Message from my data entry viewmodel to my treeview view model.

Though the message is recieved, the tree doesnt get refreshed. I called LoadChildren on each node again, and used RaisePropertyChanged as well but the data didnt get updated.

Best Answer

The TreeView is bound to a hierarchical collection in your ViewModel, and it has a property name, e.g. TreeViewData. Assuming your ViewModel implements INotifyPropertyChanged, simply call the PropertyChanged handler for property TreeViewData. This will completely refresh the TreeView.

Related Topic