Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigating between Views in WPF MVVM

I am new to WPF and MVVM and am working on an application which has a few views. Right now I have a View(HomePageView) shown in the shellView's context. Now using a button in the HomePageView I want to load another View in place of the currently shown HomePageView. After looking it up on google, I found something about Event Aggregators. I would request someone to explain the implementation or direct to a good sample application.

like image 674
Pranjal Avatar asked Mar 22 '13 17:03

Pranjal


People also ask

How do you navigate from one XAML page to another in WPF MVVM?

To package content for navigation, WPF provides the Page class. You can navigate from one Page to another declaratively, by using a Hyperlink, or programmatically, by using the NavigationService. WPF uses the journal to remember pages that have been navigated from and to navigate back to them.

Can one ViewModel have multiple views?

You can create One ViewModel for multiple views.

Should ViewModel handle navigation?

Navigation should always be handled in the ViewModel. You're on the right track with thinking that the perfect implementation of the MVVM design pattern would mean you could run your application entirely without Views, and you can't do that if your Views control your Navigation.


1 Answers

If your new to WPF MVVM I'd suggest first picking a decent helper tool

There are quite a few options. MVVM Light, Prism, MEF

I'd suggest MVVM light. Simple and easy to get up and running. Prism isnt solely a MVVM Helper but includes features to assist with MVVM. Not done much with MEF myself or things like Caliburn Micro.

As for a sample to explain how navigation between views work with MVVM Light try:

http://www.codeproject.com/Articles/323187/MVVMLight-Using-Two-Views

MVVM Light on CodePlex:

http://mvvmlight.codeplex.com/

^^ link has forwards to some video presentations totally worth watching

Another nice sample using MVVM Light:

http://apuntanotas.codeplex.com/

These should help you get started and you always got https://stackoverflow.com/questions/tagged/wpf for particular questions :)

like image 173
Viv Avatar answered Sep 23 '22 21:09

Viv