Introduction
In this article we will discuss how to navigate between pages using Xamarin Forms. Page Navigation is used to switch between two or more pages in an application.
Prerequisites
In this article we will discuss how to navigate between pages using Xamarin Forms. Page Navigation is used to switch between two or more pages in an application.
Prerequisites
- Windows10
- Visual Studio 2017 Community Edition
- Xamarin Package
Step 1
Open Visual Studio 2017 Community Edition then go to File -> New -> Project click on Project. Now, a new window will open in that window under installed select Visual C# -> Cross -Platform. Now, select Cross Platform App (Xamarin), now give the name of the project and set the location for that folder and then click OK.
Step 2
Now a new window will open. In that window select Blank App and then select Xamarin.Forms and select Portable Class Library (PCL) and click OK.
Step 3
Now, select the Minimum Version and Target Version for UWP application and then click OK.
Step 4
Now, in Solution Explorer under Portable class right click and go to Add -> New Item and click on it.
Now, a new window will open; in that window under installed select Visual C# select Content Page and give the name of that file i.e., when we click on navigate button then it will navigate to this page and click OK.
Step 5
Now, in Solution Explorer under Portable expand App.xaml and select App.xaml.cs file.
Now, under public add the navigation command:
C# Code
MainPage = new NavigationPage(new Page_Navigation_Using_Xamarin_Forms.MainPage());
Step 6
Now open the MainPage.xaml file and set the Title of the MainPage and write the XAML code for MainPage.
XAML Code
Open Visual Studio 2017 Community Edition then go to File -> New -> Project click on Project. Now, a new window will open in that window under installed select Visual C# -> Cross -Platform. Now, select Cross Platform App (Xamarin), now give the name of the project and set the location for that folder and then click OK.
Step 2
Now a new window will open. In that window select Blank App and then select Xamarin.Forms and select Portable Class Library (PCL) and click OK.
Step 3
Now, select the Minimum Version and Target Version for UWP application and then click OK.
Step 4
Now, in Solution Explorer under Portable class right click and go to Add -> New Item and click on it.
Now, a new window will open; in that window under installed select Visual C# select Content Page and give the name of that file i.e., when we click on navigate button then it will navigate to this page and click OK.
Step 5
Now, in Solution Explorer under Portable expand App.xaml and select App.xaml.cs file.
Now, under public add the navigation command:
C# Code
MainPage = new NavigationPage(new Page_Navigation_Using_Xamarin_Forms.MainPage());
Step 6
Now open the MainPage.xaml file and set the Title of the MainPage and write the XAML code for MainPage.
XAML Code
- <?xml version="1.0" encoding="utf-8" ?>
- <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Page_Navigation_Using_Xamarin_Forms" x:Class="Page_Navigation_Using_Xamarin_Forms.MainPage" Title="First Page">
- <StackLayout VerticalOptions="Center" HorizontalOptions="Center">
- <Label Text="This is the first page of this application" FontSize="Medium" />
- <Button Text="Navigate to Second Page" Clicked="Onbtn_Clicked" BackgroundColor="Blue" /> </StackLayout>
- </ContentPage>

Vijayaragavan SPosted Jun 7, 2018, 10:35 PM
Nice Article.... Keep writing.....