I want to create a “Wizard” in my Silverlight MVVM application. The Wizard should contain multiple steps between which you can navigate using “next” and “previous”.
The problem I am facing is the relationship between views and view models.
I want there to be a view and view model for the Wizard itself. My instinct tells me that there should be one view/view model pair for each step in the wizard.
What is a good approach for maintaining these kinds of relationships, where one view model holds several other view models and the view actually consists of several smaller views?
Are there any patterns or practices that I can use?
I know this question might be subjective, but give me the rough cuts of an approach and I’ll award you an answer!
I’d propose main wizard viewModel which has a collection of
stepsview models and handles navigation between them. While navigating it should call validation methods instepviewModels:WizardVM:
WizardView:
UPDATE:
Views can be coupled with ViewModels via
Datatemplating. For example add this into resources inApp.Xaml:Your viewModels should know absolutely nothing about views. It means that
WizardVMshouldexpose only other viewModels but not views. It’s a rule of thumb for MVVM.
UPDATE2 Oops, I forgot that Silverlight doesn’t have DataTemplating yet. In silverlight I would still expose ViewModels but bind them to
ContentPresentersusing a converter which will convert a viewModel into corresponding view.