Dipping my toe in Xamarin; Hot Tip for Navigation.

I’ve been tinkering in Xamarin, to allow my development to more easily target multiple mobile platforms.

I’ve made a start on two apps, and I just hit a little wall that was easily fixed but I thought was worth sharing:

The Xamarin tutorials show navigation as being done with a “Push” like this:

await Navigation.PushAsync (new Page2Xaml ());

Which is great, except it doesn’t work out of the box.

The issue is for this to function, you need your app to be utilizing a NavigationPage element.  A Navigation page is a page which holds other pages and navigation… I suppose (very) roughly like a Frame in UWP.

But the default templates don’t include one.  So the easy way to change it is to go to your App.xaml.cs and change the constructor from opening a regular page like this:

MainPage = new MyAppName.Views.MainView();

to this creating a NavigationPage and then “Push”-ing to the start view**:

var p = new NavigationPage();
MainPage = p;

p.PushAsync(new MyAppName.Views.MainView());

Now your whole application exists within the NavigationPage element and navigation should work as intended.

Rob,
Valley Software.

 

** Yes the var is not required, however this is a logical layout to show the example.