Navigation Page in Xamarin Forms XAML

A NavigationPage makes it very easy to create a browser like navigation stack of pages with a back button. It is a container for your pages so the XAML to for your ContentPage doesn't change, but when the app starts and you first create the page you put it inside a NavigationPage like this:

public static Page GetMainPage()
	return new NavigationPage(MyPage());

Now we have a navigation page, you'll need a new page to navigate too, so create a new page and then on your first page add a button like this:

<Button Text="Press me" Clicked="OnClicked"/>

You'll then need to add an event handler to the page's code behind:

protected async void OnClicked(object sender, EventArgs args)
	await Navigation.PushAsync(new MyNewPage());

This adds a navigation bar to your screen showing the current page title. The page title can be set in XAML on your ContentPage or in code. If you click the button you will be taken to MyNewPage and a back button will be shown in the navigation bar that will take you back.

Other Page Controls

No Comments