Region navigation to ViewModel

Topics: Prism v4 - Silverlight 4, Prism v4 - WPF 4
Mar 24, 2011 at 12:33 AM

Hi, it's said in the documentation that it's possible to use regions navigation mechanism to navigate to ViewModels. But how it can be implemented in practice?

Mar 24, 2011 at 9:14 PM

The only way I currently see is to implement INavigationAware for a ViewModel, and when I call RequestNavigate method for this ViewModel, I can handle incoming request in OnNavigatedTo method and using injected IRegionManager explicitly set appropriate view for neccessary region. But it looks like just a way to publish a navigation event and to do all the work manually. In this case the benefit from region navigation mechanism is minimal.

Developer
Mar 28, 2011 at 3:35 PM

Hi,

Navigation to a ViewModel can be useful when using the ViewModel-First approach in the MVVM pattern defining the View as a DataTemplate of the ViewModel.

The following note in the Navigation Chapter from the Prism MSDN documentation might clarify the aforementioned:

"The preceding description illustrates view-first navigation, where the URI refers to the name of the view type, as it is exported or registered with the container. With view-first navigation, the dependent view model is created as a dependency of the view. An alternative approach is to use view model–first navigation, where the navigation URI refers to the name of the view model type, as it is exported or registered with the container. View model–first navigation is useful when the view is defined as a data template, or when you want your navigation scheme to be defined independently of the views."

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Mar 30, 2011 at 11:04 AM

Hi Guido,

Thanks for reply. I've read documentation and it was actually original cause of the question ). The main question I try to find out now is how to show View if I navigate to ViewModel.

Developer
Mar 30, 2011 at 3:12 PM

Hi,

You might find an example of how to define a DataTemplate to specify how you wish to render your ViewModel in the UI in the MVVM QuickStart. You'll find more information regarding that in the section titled "Data Templates" in the MVVM QuickStart's article.

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi