views:

417

answers:

1

I am new to WPF, and I am trying to implement MVVM with TreeView according to an example. However, in addition to the functionality in the example I would like to be able to add nodes to the tree (i.e. add new child to a specific node in the tree during runtime).

My question is, should the new nodes be added to
(a) the model or to
(b) the view-model?
How changes to one of them effects the other?

+5  A: 

They should be added to the ViewModel, which will add them to the model (to keep consistency between the model and the ViewModel). In the ViewModel, the collection of child nodes should be an ObservableCollection<T>, so that the UI is notified when a node is added/removed

Thomas Levesque