Navigation Service (Day 2)

In Xamarin Forms you access navigation via the NavigationPage. A single NavigationPage contains all the page you Push to the stack and you pop them out when done. Its works like exactly like a LIFO (Last In First Out) queue.

Its easy and simple but not if you want to keep any form of control over the Navigation Stack and create different stacks (as I will get into later in the series). Why do you want a centralized Navigation Service?

  1. Go to a page via a key (not a direct reference to a page)
  2. Control the Page Build process (an important step coming up later)
  3. Provide appropriate locks and controls over moving to a new page
  4. Provide Page Cleanup (will come up later as well)

If you want to see how I have implemented a Navigation Helper you can look at my ExtNavigationService.cs

The navigation service is simple:

  1. On construction give it the NavigationPage and IPageService (this is the page constructor service, I will talk about later).
  2. Map a string to a page type via the Map method.
  3. Push and Pop via the NavigateTo and GoBack methods.

Navigation Service

The NavigationService then implements an interface and is registered in the IoC container for use where appropriate in your app. A list of string keys is normally kept in a file as constants, that should be easily accessible to the code that requests navigation commands as you can see in my PageLocator.cs class.


5 Common Pitfalls In Enterprise Mobile Development

Based on my experience, of over 9,000hrs of Xamarin.Forms development, check out some of my hard learnt lessons, in enterprise Xamarin.Forms development.
Check out 5 Common Pitfalls In Enterprise Mobile Development.

<< Silos and Low Dependencies (Day 1) ||  Page Building and Cleanup (Day 3) >>

14 Days To Building An Enterprise Quality Xamarin Forms App


Posted

in

by

Tags: