tags:

views:

586

answers:

2

I'm using MVVM in a WPF application. I want the least possible code to exist in the view's code behind. All Views and ViewModels are registered in dependency injection engine and my Views have dependencies to their ViewModel (injected via constructor).

In one of the command handlers of ViewModel "A", I need to show View "B". What's the best approach to create the second view? I can resolve it via Constructor of ViewModel "A", and display it in the command handler, or resolve it with Service Locator when the command is being executed.

+1  A: 

If you've already got a service locator, then use it.

See also this question.

David Schmitt
A: 

Another way is to put the responsibility of showing views out from the ViewModel into a Controller. This way the ViewModel doesn't need to know about other ViewModels and the Controller is the mediator between them.

How this can be accomplished is shown in the sample applications of the WPF Application Framework (WAF) project.

jbe