Wednesday, 18 March 2015

Page Navigation in Windows Phone 8.1

Hello Every One,


How to Page Navigation  in Windows phone 8.1 application?

This Post shows you how to navigate pages in windows phone 8.1 and how to pass parameter in other pages also.

Step 1:

Open Visual Studio 2013 create new Project in windows phone app. Select Blank App(Windows Phone) and give application name and location.

Step 2:

Open MainPage.xaml file and select one Button from toolbox panel, set Button content with "go to page 2".

Button is for navigate to second page.



Step 3:

Now Add one new Bank Page form Solution Explorer right-click, add new item. Give Page name as "Page2.xaml".



Step 4:

Now in Page.xaml add one Button and one Textblock from toolbox, set Button content with "go to page 1" and Textblock Text with "Value : ".

Button is for navigate to first page and textblock will show the parameter value.



Step 5:

Now go to MainPage.xaml and add Button click event and write code like this :



Step 6:

Same as go to Page2.xaml and add Button click event write code like this :


Now Run the Project and click on button you will navigate form one Page to another.

Step 7:

Now how to pass parameter in other page?

In Button event of MainPage.xaml write code like this :



Now go to Page2.xaml.cs file in OnNavigated Method write code like this :



Now Run the Project again and click on button you will receive value in textblock ; 



Step 8:

You can send multiple value or object as a parameter.
for that you have to add one Class file and give name as MyClass. And declare two variable inside the class like this :



Now go to MainPage.xaml.cs file in button click event declare MyClass Object and pass as parameter like this :


Step 9:

Now go to Page2.xaml.cs in OnNavigated Method write code to get object value like this :

Now again Run the Project and click on button you will navigate on Page2.xaml and get Output like this: 
Thank You.

No comments:

Post a Comment