Windows Phone7 page navigation

Source: Internet
Author: User

Address: http://www.cnblogs.com/xieLongBao/archive/2012/02/26/2368377.html

 

Learn WP7 development with Mr Lin Yongjian

  • Content Overview
  • Use xaml for navigation
  • Use C # code for navigation
  • Address alias
  • Data transmission between pages
  • Back button

To better control navigation, we need to know the architecture and framework of the page:

  • Frame
    • Only one separate PhoneApplicationFrame
    • Contains one or more phoneapplicationpages
    • It also contains the system tray and application bar
  • Page
    • Contains titles and can have independent application Columns
    • Page navigation
  • SIlverlight for window phone uses page-based page navigation
    • Similar to web page navigation
    • Each Independent URI has a unique URI.
    • Each Independent page is stateless.

After the introduction, the following is an example:

  • Use navigation in XAML

A very important control in the navigation: hyplinkbutton, So I first drag four hyplinkbuttons to the interface,

This is the home page. Next, create a new navigation page Music. xaml to the views directory, and add contant as the NavigateUri of the Music hyperlinkbutton.

In this way, you can start the program and navigate to the following three items according to the same operation,

    • Use C # code for navigation (using a very important class)

    • Step 3 is required to use an alias for navigation: Step 1 defines the ing rules in the App. xaml file, and step 2 initializes the defined Resource in App. xaml. cs.

      The second part initializes the Resource defined in App. xaml. cs.

Step 3: Use it on the page, modify the NavigationURi attribute of HyperLinkButton to the following, and complete the alias navigation.

?
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">        <HyperlinkButton Content="Music" Height="30" HorizontalAlignment="Left" NavigateUri="Music" Margin="29,131,0,0" Name="hyperlinkButton1" VerticalAlignment="Top" Width="115" />        <HyperlinkButton Content="Video" Height="30" HorizontalAlignment="Left" NavigateUri="Vedio" Margin="29,60,0,0" Name="Vedio" VerticalAlignment="Top" Width="115" />        <HyperlinkButton Content="Browser" Height="30" HorizontalAlignment="Left" NavigateUri="WebBrowser" Margin="29,283,0,0" Name="WebBrowser" VerticalAlignment="Top" Width="115" />        <HyperlinkButton Content="Image" Height="30" HorizontalAlignment="Left" NavigateUri="Picture" Margin="29,207,0,0" Name="hyperlinkButton4" VerticalAlignment="Top" Width="115" />                <Button Content="Music" Height="72" HorizontalAlignment="Left" Margin="241,131,0,0" Name="musicbutton1" VerticalAlignment="Top" Width="160" Click="musicbutton1_Click" />        <Button Content="Video" Height="72" HorizontalAlignment="Left" Margin="241,39,0,0" Name="videobutton2" VerticalAlignment="Top" Width="160" Click="videobutton2_Click" />        <Button Content="Browser" Height="72" HorizontalAlignment="Left" Margin="241,323,0,0" Name="webbroserbutton3" VerticalAlignment="Top" Width="160" Click="webbroserbutton3_Click" />        <Button Content="Image" Height="72" HorizontalAlignment="Left" Margin="241,225,0,0" Name="picturebutton4" VerticalAlignment="Top" Width="160" Click="picturebutton4_Click" />    </Grid>
  • Data is transmitted between pages. The most common method is to transmit data through QueryString ,?
    <HyperlinkButton Content="Song 1" NavigateUri="/Views/Music. xaml? Song = song 1" Height="30" HorizontalAlignment="Left" Margin="175,230,0,0" Name="hyperlinkButton2" VerticalAlignment="Top" Width="200" /> 

    When the Music. xaml page is loaded, the passed parameters are displayed,

    ?
    using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using Microsoft.Phone.Controls; namespace PageNavigation.views{    public partial class Music : PhoneApplicationPage    {        public Music()        {            InitializeComponent();        }         private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)        {            if (NavigationContext.QueryString.Count > 0)            {                textBlock1.Text = NavigationContext.QueryString["song"];            }        }     }}

      

  • To pass parameters using aliases, you must first modify the ing rules in App. xaml.

Modify the page

?
<HyperlinkButton Content="Song 1" NavigateUri="Music/Song 1" Height="30" HorizontalAlignment="Left" Margin="175,230,0,0" Name="hyperlinkButton2" VerticalAlignment="Top" Width="200" />

Note: NavigationService cannot pass objects by default (you can use static properties of the App class, SIngleton class, and break down the object into QueryString to pass ......)

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.