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