I have a WPF application that uses the mvvm pattern and I need to show a dialog from my principal view model.
I have a secondary view with its view model, and I think that I have two options to create the dialog.
OPTION 1
In the principal view model I can do the following:
- Create the view of the dialog
- Create de view model of the dialog
- Assign the view model to the view
- ShowDialog
OPTION 2
In the principal view model:
- Create the view model of the dialog
In the constructor of the view model of the dialog:
- Create the view of the dialog
- Assign the view model to the view. In this case is assign "this"
- ShowDialog
I know that in MVVM the view model has to know nothing about the view, but in the second option, in practice, how the view model has not any property that link to the view, only is create an showed in the constructor, in the final state the view model does not know nothing about the view.
However, I think that the code in the principal view is clearer, because I only need to create the view model, only one line of code, instead of the option 1 that need 4 lines (create the view, cretate the view model, assign the view model to the view and show the dialog).
Am I wrong in thinking that the second option is not a bad idea if I want to follow the mvvm pattern?