How to perform page navigation on Windows Phone
- It is similar to activity in android programming
- There are following steps for page navigation in windows phone
In this section, you will create an additional page of content that you can navigate to from your app main page.
To create an additional page
- Create a new project by selecting the File | New Project menu command.
- The New Project window will be displayed. Expand the Visual C# templates, and then select the Windows Phone templates.
- Select the Windows Phone App template. Fill in the project name as desired.
- From the designer view on MainPage.xaml, select page title and change this title text tomain page in the Text properties or in the XAML directly.
- Right-click your project name in the Solution Explorer, select Add from the menu, and thenNew Item.
- Choose Windows Phone Portrait Page, change the name to SecondPage, and select Add at the bottom of the page.
- From the designer view on SecondPage.xaml, select page title and change this title text tosecond page in the Text properties or in the XAML directly.
This section will show you how to navigate back and forth between your MainPage.xaml andSecondPage.xaml.
To navigate between pages
- On MainPage.xaml, drag a HyperlinkButton control from the Toolbox onto the designer surface. Select the control and change the Content property to Navigate to Second Page or do this directly in the XAML. You may need to expand the control width to see all of the text.
- Double-click the hyperlink button to add an event handler for the hyperlink click event. TheMainPage.xaml.cs file will open.
- For the hyperlinkButton1_Click event handler, add the following code:
private void hyperlinkButton1_Click(object sender, RoutedEventArgs e) { NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative)); }
You can also accomplish the above in the MainPage.xaml by setting theNavigateUri property for the hyperlink control to the second page. For example:NavigateUri = “/SecondPage.xaml” - On SecondPage.xaml, drag a Button control onto the designer surface. Select the control and change the Content property to Navigate Back to Main Page or do this directly in the XAML. You may need to expand the control width to see all of the text.
- Double-click the button to add an event handler for the button click event. TheSecondPage.xaml.cs file will open.
- For the button1_Click event handler, add the following code:
private void button1_Click(object sender, RoutedEventArgs e) { NavigationService.GoBack(); }
- Run the app by selecting the Debug | Start Debugging menu command. This will open the emulator window and launch the app.
When you run the app, you will see that it consists of two pages: the main page and a second page. You can navigate from the main page to the second page using a hyperlink with the destination URI configured in its event handler. You can return from the second page to the main page by using theGoBack() method of the navigation service.
Although the GoBack() method was used in this example, the hardware Back button would also have the effect of returning to the previous page.
|
No comments:
Post a Comment