Windows Phone 7 page navigation

Source: Internet
Author: User

1. General page navigation

Use the navigateuri attribute of the hyperlinkbutton control to navigate between pages.

Example: 

Navigateuri: The relative address of the navigation page.

2. Use the button control to navigate.

Because the button control does not support navigation attributes such as navigate, we use the navigationservice's navigate method to implement page navigation.

For example, register the Click Event of the button control and add the following code:

         private void btn_Movies_Click(object sender, RoutedEventArgs e)        {            NavigationService.Navigate(new Uri("/Views/Musics.xaml",UriKind.Relative));        }

In this way, you can also navigate the page.

The preceding navigation is to use the relative path of the page for navigation. You can also use an alias for navigation. This is similar to the alias navigation used by web development. See the following explanation.

3. Use an alias for navigation.

First, add a namespace in the app. XAML file.

xmlns:nav="clr-namespace:System.Windows.Navigation;assembly=Microsoft.Phone"

To use the alias navigation, you must use the namespace added above.

Then

<Application.Resources></Application.Resources>

Add the following content to map the navigation page to the resource file.

<Application.Resources>        <nav:UriMapper x:Key="UriMapper">            <nav:UriMapping Uri="Musics" MappedUri="/Views/MusicsPage.xaml"/>            <nav:UriMapping Uri="Movies" MappedUri="/Views/MoviesPage.xaml"/>            <nav:UriMapping Uri="Ebooks" MappedUri="/Views/EbookPage.xaml"/>            <nav:UriMapping Uri="SurferInternet" MappedUri="/Views/SurferInternetPage.xaml"/>        </nav:UriMapper>    </Application.Resources>

Code explanation:

Application. resources indicates the resources of the application. urimapper can be viewed as a navigation map with some tags to indicate each page, we call these tags the alias of each page (the alias cannot be repeated). Each page has a unique address, which is usually indicated by a relative path, the mappeduri attribute indicates the path or address on the navigation page.

The code above can be seen as marking four places on a map: musics, movies, ebooks, and surferinternet. They all have unique paths and names. You can access these identifiers (reference aliases) to navigate to the corresponding page.

To add the above Code, add the following code at the public app () {...} in the app. XAML. CS file:

 public App(){   this.RootFrame.UriMapper = Resources["UriMapper"] as UriMapper;}

The role is to set the urimapper attribute of the main framework of the application to the resource file we wrote previously. It can be seen that a map indicating each page is assigned to urimapper, so that we can call it.

Call method:

First declare a hyperlinkbutton control and set navigateuri as the alias of the corresponding page. For example:

<Hyperlinkbutton content = "Music" Height = "30" horizontalalignment = "Left" margin ="
Name = "musicshyperlinkbutton" verticalignment = "TOP" width = "200" navigateuri = "musics"/>

In this way, the alias navigation of the page is realized.

TIPS: see http://www.cnblogs.com/potential/archive/2012/11/03/2752826.html.

NOTE: For the above content, refer to the Windows Phone video of jacklin.

(All Rights Reserved. For details, refer to the source)

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.