PRISM 101: Navigation

Hector Minaya
May 4, 2017 · 2 min read
Image for post
Image for post

The best MVVM framework for Xamarin Forms :)… Honestly, don’t trust me, trust this guy

Image for post
Image for post

There is no way I can cover all that PRISM has to offer in a single blog post, so I’ll concentrate one of my favorite features: Navigation!.


Image for post
Image for post

And this is how it feels when using the Navigation Service in PRISM

Image for post
Image for post

How does it work?

Notice the RegisterTypes() method.

Now, if you embrace MVVM you’ll agree that navigation takes place in the ViewModel. We do this by injecting INavigationService in our constructor.

Then we can use _navigationService.NavigateAsync(“PageNameHere”) to load a page into the navigation stack or _navigationService.GoBackAsync() to pop a page from the stack. As simple as that!

What about parameters? Glad you asked

For this we have the NavigationParameters object, we can use this to pass along parameters, but be careful not to send too much information.

Now, how do we receive the parameters on the other end?

Simple, use use the same NavigationParameters object:


By implementing this interface we have access to 3 new methods

This is where we can inject ourselves before the we navigate to the next Page.

This method is executed when another page navigates to us. This is called after the ViewModel has been pushed on to the stack.

Finally (this one is new in PRISM 6.3), the difference between this one and OnNavigatedTo is that this is called before the ViewModel has been pushed on to the stack.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store