MVVM with TreeView - add nodes

How can I add nodes to the tree (for example, add a new child to a specific node in the tree at runtime) in this example TreeView?

Should new nodes be added to
(a) model or
(b) view model?
How does one change affect the others?

+2


source to share


1 answer


They must be added to the ViewModel, which will add them to the model (to maintain consistency between the model and the ViewModel). In the ViewModel, there should be a collection of child nodes ObservableCollection<T>

so that the UI is notified when a node is added / removed



+6


source







All Articles