Both types of browsing and browsing should work on some NodeViewModel . You do not need separate viewing models for different viewing scenarios only.
Now can you edit the node not yet shown to the user? If not (as in the case, the user decides what is being edited), view models should be created for the first time when their content should be presented to the user. In most cases, this would be in some browser views / details so that the user can select an item and then decide to edit it.
Edit
Regarding your comment. NodeViewModel must be provided to view the editor.
The providing part can be performed, for example, by injection of the constructor or by setting the context of the presentation data manually. For example, when a user views all nodes in the browser view, he can double-click on the list item and an editor pop-up window appears:
// this will probably be done in response to event private void ListItemDoubleClick(object sender, EventArgs e) { NodeViewModel currentItem = // extract current list item EditorView editorView = new EditorView(currentItem); editorView.Show(); }
Alternatively, if you want to avoid such a strong connection between CompositeView and EditorView , you can always use events, however this is not always necessary.
Another thing that I was thinking about in terms of design is to add an additional view model, name it NodesListViewModel . What the program stream might look like:
- When you start the application, get your nodes (whether from a database, file, service, etc.)
- Create an instance of
NodeListViewModel that accepts a dependency on IList<Node> (list of node objects) NodeListViewModel will create and expose a collection of NodeViewModel elements- Create an instance of your main program window that uses the composite view. It needs a
NodeListViewModel as a data context. - When the user decides that he needs to edit the item, everything is ready. The browser has a list of all
NodeViewModels , it can easily pick up the current one and transfer it to the highlighted view.
source share