Am I doing right ? Use of viewmodel in overall app + new datawindow

Topics: Questions
Apr 28, 2013 at 6:56 PM
Edited Apr 28, 2013 at 7:00 PM
Hi there.
First of all, thanks for this well-stuffed framework. There are so many thing and I don't even use the half of them.
I have a few questions about the use and the logic of MVVM and this framework.

Let say I have a big WPF application which is composed into several parts. The main parts are these following : a menu, a statusbar, a navigation and properties panel.
Though they have their logic, they refer to some common "models". Theses models are nested in a bigger model that I called "Engine". As it speaks for itself, it also contains business logic of the application.
Hence, I have 1 datawindow (the main one) with its viewmodel bound to the Engine model.
This datawindow is composed by four other usercontrols (menu, navigation panel, etc.) and their viewmodel also bound to the same Engine model.
Though I am not encountering any issues by doing like this, do you think that I could have serious trouble soon ? Is it fine to share a model like that ?

I told you before about the existence of a navigation panel. It's a project browser in a treeview (like Visual Studio project browser). That leads to my next question. I want to reorganize this treeview but through a modal window.
I did a new datawindow with its viewmodel. But the model remains the Engine.
When I do that, Catel is trying to serialize the whole model. I understand why it's doing that, because it has be able to go back to the previous state if I press cancel button.
But I don't want a window which put my model into an editing state. This modal window is just an helper. How can I prevent Catel to do that ? Although, I want to have the notification of properties changed in that window.

And my last question is related to that new window and the navigation panel. As I said, the navigation is a project browser in a treeview. That means I have a Project model inside my Engine model. A Project model which contains children models and so on.
Going back to the window. I have access to the Engine model, thus the Project model (which is bound to the treeview in the navigation panel). If I begin to modify the Project (name, children etc.), it notifies the viewmodel of the new window (so far so good), but also the main window.
How to tell the main window, especially the navigation treeview, to update itself only when the edition is complete ? Shall I make a clone ? How to proceed in this case ?

Thanks :)
Coordinator
Apr 29, 2013 at 2:30 PM
Thank you very much for the kind words.

1) You can share the same models between several view models. For such high-level controls, I normally create services that the view model can call, but you can also share the models among all view models. Both ways are find.

2) The ViewModelBase constructor has an overload which allows you to specify "supportIEditableObject". Just set it to false.

3) Yes, it's best to have 1 view model to be responsible to undo/redo actions. Another way is to use the MementoService and add each change to the service. Then you can support Undo/Redo stuff and you don't have to serialize/deserialize the objects yourself.
Apr 29, 2013 at 2:59 PM
Thanks for this quick reply. It's really appreciated.

1) I feel assured that I am on the right track.

2) Great, that will help me a lot

3) Okay. I think I might have another way out. I'll use a dedicated model (like a wrapper with nested wrappers for nested models) for this datawindow. It will be initialized before the window pops on the screen. Like that, every changes in that window can be rollbacked if necessarily, and the project browser won't be updated at the meantime (it won't be the same objects).
Once the window is closed, I apply these changes to the reals models.

Thansks again for your time and keep going on this good job.