Windows phone8.1: Detailed page navigation

Source: Internet
Author: User

Little Dream brings you the Windows Phone 8.1 app development Practice tutorial, sharing your own learning, development process experience and skills.

Share your knowledge about Windows Phone 8.1 page navigation today. The relevant points of knowledge are as follows:
    1. Page one navigation to page two
    2. Page one parameter navigation to page two
    3. Page number of parameters to navigate to page two
    4. Overrides the back key so that the back key returns to the previous page. Note: The back key defaults to exiting the program.
    5. Clear back stack history.

In this case, there are three pages: Mainpage,blankpage1,blankpage2.

Mainpage,blankpage1 's foreground code is as follows:

<Grid>
<Grid.RowDefinitions>
<rowdefinition height= "Auto"/>
<rowdefinition height= "/>"
<rowdefinition height= "/>"
<rowdefinition height= "/>"
<rowdefinition height= "*"/>
</Grid.RowDefinitions>
<textblock text= "This is the homepage" grid.row= "0" fontsize= "></TextBlock>
<stackpanel grid.row= "1" orientation= "Horizontal" >
<textblock text= "website:" fontsize= "," margin= ", 0,0,0,30" width= "/>
<textbox x:name= "Textname" height= "All" margin= "0,10,0,0" width= "260"/>
</StackPanel>
<stackpanel grid.row= "2" orientation= "Horizontal" >
<textblock text= "URL:" fontsize= "" margin= "0,0,0,30" width= "[/>]
<textbox x:name= "textadress" height= "All" margin= "0,10,0,0" width= "260"/>
</StackPanel>
<stackpanel grid.row= "3" orientation= "Horizontal" >
<textblock text= "content:" fontsize= "margin=" 0,0,0,30 "width="/> "
<textbox x:name= "Textcontent" height= "All" margin= "0,10,0,0" width= "260"/>
</StackPanel>
<button content= "Go to the second page" grid.row= "4" margin= "122,147.667,0,147" click= "Button_Click"/>

</Grid>

BlankPage2 's foreground code is as follows:
1<Grid>2<Grid.RowDefinitions>3<rowdefinition height="Auto"/>4<rowdefinition height=" the"/>5<rowdefinition height="*"/>6</Grid.RowDefinitions>7<textblock text="This is Page three ."grid.row="0"Fontsize=" +"></TextBlock>8<textbox name="text"grid.row="1"height=" -"margin="0,9.667,10,0"/>9<button content="I want to go directly to the homepage"grid.row="2"margin="122,147.667,0,147"click="Button_Click"/>Ten</Grid>

MainPage's background key code is as follows:
1 Private voidButton_Click (Objectsender, RoutedEventArgs e)2 3 {4Website web=NewWebsite ()5 {6Name= This. Textname.text,7address= This. Textadress.text,8Content= This. Textcontent.text9 };TenFrame.navigate (typeof(BlankPage1), web);//corresponding to the knowledge point 3, that is, when passing multiple parameters to establish an object, passing the object can be.  One}
Blankpage1 's background key code is as follows:
1 protected Override voidOnnavigatedto (NavigationEventArgs e)//overrides Onnavigatedto accepts parameters that are passed from the Maingape page. 2 {3 varweb =(Website) e.parameter;4  This. Textname.text =web. Name;5  This. Textadress.text =web. Address;6  This. Textcontent.text =web. Content;7hardwarebuttons.backpressed + = hardwarebuttons_backpressed;//Register rewrite Back button events8 }9 Ten Private voidHardwarebuttons_backpressed (Objectsender, Backpressedeventargs e)//rewrite the back button and if you want to use it for all pages, you can rewrite it in the App.Xaml.cs app initialization function.  One { Ae.handled =true; -  - if(Frame.cangoback) the Frame.goback (); - } -  - Private voidButton_Click (Objectsender, RoutedEventArgs e)//passing a single parameter +  - { +Frame.navigate (typeof(BlankPage2),"I sent it from the second page!! "); A}

Key backend code for BLANKPAGE2:
1 protected Override voidonnavigatedto (NavigationEventArgs e)2 {3Text. Text = (string) E.parameter;4Frame.BackStack.RemoveAt (Frame.backstackdepth-1);//corresponding to the Knowledge point 5, clear back the last history of the stack, in this case, the second page, deleted from the third page directly to the homepage. 5 }6 7 Private voidButton_Click (Objectsender, RoutedEventArgs e)8 {9 Frame.goback ();Ten}

Operating effect:

Source code Download:

Page navigation Source code

PS: Want to love windows Phone development of the great God, small white can come to programming small dream together a lot of communication, Windows Phone developer itself is relatively few, small dream hope we have a platform for communication, welcome everyone to visit!

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.