Windows Phone development experience (2)-page navigation

Source: Internet
Author: User
Navigationservice: used to process the navigation of Windows Phone pages

 

Common attributes

Attribute name

Description

Backstack

ObtainIenumerableUsed to enumerate entries in the back navigation history.

Cangoback

Gets a value that indicates whether at least one entry exists in the back navigation history.

Cangoforward

Gets a value that indicates whether at least one entry exists in the forward navigation history.

Currentsource

Obtain the Uniform Resource Identifier (URI) of the currently displayed content ).

Source

Gets or sets the Uniform Resource Identifier (URI) of the current or navigation content ).

 

 

Common Methods

Method Name

Description

Goback ()

Navigate to the latest entry in the back navigation history. If there are no entries in the back navigation, an exception is thrown. So here we will pay attention to it. We can first determine whether we can retreat, and then use the cangoback attribute we introduced above.

Goforward ()

Navigate to the latest entries in the forward navigation history. If there are no entries in the forward navigation, an exception is thrown. For Windows Phone, this method always raises an exception because there is no Forward Navigation stack. Similarly, we also need to determine whether we can navigate to the next page [cangoforward]

Navigate (URI)

Navigation of the content specified by the Uniform Resource Identifier (URI. The parameter is a URI object.

 

 

Navigationcontext

Function and description:The status of the navigation operation.

 

Common attributes

Attribute name

Description

QueryString

 

Obtains the set of query string values. The result is an idictionary <string, string> key-value pair.

 

Demo example:

First, let's look at the implementation effect.

 

Main source code:

Mainpage. XAML

<Grid X: Name = "contentpanel" grid. row = "1" margin = "53,220,"> <button content = "Jump to the second page with the parameter" Height = "72" horizontalalignment = "Left" margin =, 352 "name =" button1 "verticalignment =" TOP "width =" 27,107 "Click =" button#click "/> <textblock Height =" 30 "horizontalalignment =" Left "margin = ", 0, 0 "name =" textblock1 "text =" parameter value: "verticalalignment =" TOP "/> <textbox Height =" 72 "horizontalalignment =" Left "m Argin = "129,84," name = "textbox1" text =... "Verticalalignment =" TOP "width =" 460 "/> </GRID>

 

The click event added by mainpage. XAML. CS for the button

Private void button#click (Object sender, routedeventargse) {// create a URI object URI uri = new uri ("/second. XAML? MSG = "+ textbox1.text, urikind. Relative); // navigate to navigationservice. navigate (URI );}

 

Layout in second. XAML file:

<Grid X: Name = "contentpanel" grid. row = "1" margin = "12, 0, 12, 0"> <textblock Height = "30" horizontalalignment = "Left" margin = "9, 69, 0, 0 "name =" textblock1 "text =" the value from the first page: "verticalalignment =" TOP "/> <textblock Height =" 30 "horizontalalignment =" Left "margin =" 214,69, 0, 0 "name =" textblock2 "text =" textblock "verticalalignment =" TOP "/> <button content =" back to previous page "Height =" 72 "horizontalalignment =" Left "margin = "54,230, 300 "name =" button1 "verticalignment =" TOP "width =" "Click =" button#click "/> </GRID>

 

In the second. XAML. CS file, we retrieve the passed value from the loaded event on the page.

  private voidPhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)        {            string msg = "";             if (NavigationContext.QueryString.TryGetValue("msg", outmsg))            {                this.textBlock2.Text = msg;            }        }         private voidbutton1_Click(object sender, RoutedEventArgs e)        {            if(NavigationService.CanGoBack)            {               NavigationService.GoBack();            }        }

 

If you need to reprint reference please indicate the source: http://blog.csdn.net/jiahui524

 

 

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.