I am having another go at a WPF application incorporating Prism & MEF and attempting to gain a better understanding of the MVVM pattern. I have done this before and, although I have a working solution that I am happy with, I am not convinced that I stayed true to the MVVM pattern in that I ended up with view models exposing a lot of event handlers and the code behind on the views handling these events. These events were aimed primarily at opening additional views (such as edit dialogs) based upon selections made in the initial view.
So far (this time) I have created a shell application with PRISM, I have some regions and I can create views and add them to those regions. I am also using MEF to modularise the solution as well as automatically provide the view models to the views through IoC. Again, this works - to a point...
My problem is with the creation of some of the view models. So far, I have created models that contain lists from databases. These work and so far the most code behind I have is and additional constructor with an [ImportingConstructor] attribute that ensures I get the view model. I am happy with this for the moment (but may look at options later on).
My next step is to provide a new view to edit an item in one of the lists (this is basically a classic master list opening an edit dialog). This is where I cannot see the MVVM/MEF way to do things - I cannot find a way to pass a parameter to a view model constructor based upon the currently selected item in the list.
I know I am trying to be a purist here. I also know that there is nothing wrong with code behind. I am however trying to see if the utopian implementation can actually be acheived.
So, how would you go about this...
Given a list, with a selected item, open a new view (InteractionRequest?) with a view model that contains either (a) the actual item selected in the list or (b) at least some kind of reference to it or one of its properties that can be used to retrieve the item again from the data store?