WPF MVVM - Refresh Treeview
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.
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
.
My answer is based on the fact you are using Mvvm light, since you did not provide code I will just state the obvious and it might solve your issues.
Is your viewmodel implementing the ViewModelBase interface? (which implements INotifiedPropertyChanged)
I never used TreeViews but assuming it's using a collection as its datatemplate, you have to call RaisePropertyChanged on the collection whenever you add/remove an item and also whenever an item changes. Calling RaisePropertyChanged only in the "set" of the collection won't be enough.
精彩评论