"16.Windows Phone" 16.3 Multi-page program

Source: Internet
Author: User

1. Jump between pages

    • navigateuri (page-directed jump) Hyperlinkbutton controls can easily jump between pages, just specify a URI, You can jump to the appropriate page after clicking on it. Similar to hyperlinks in the web. The written format of the URI is consistent with the previous (URI format is error-prone). Used to make a directed jump between XAML pages. URI format instance: /navigatingbetweenpages;component/otherpages/page1.xaml Navigatingbeteenpage is the project name, component/ The following is the path to the page relative to the project to jump to. Note that the front "/" can not be omitted.
    • When we write URIs, we can omit the characters that precede the root of the project, with the same functionality. For example:

      /navigatingbetweenpages;component/otherpages/page1.xaml

      otherpages/page1.xaml

    • NavigationService (C # flexible jump) When you want to jump to the page address is not fixed, you need to jump to different situations, you need to use the NavigationService in C # navigate (). This method is more flexible and controllable.
    • navigationservice (a hyperlink that implements a regular control) in addition to Heyperlinkbutton implements hyperlinks, Other general controls can also be implementation jumps as long as the Navigationserviece.navigate () specified URI of the control is set.
    • navigationservice common members

GoBack ()

One step back.

GoForward ()

Before further

CanGoBack

Determine if you can back up if there is no previous page, call GoBack () will error

    • Frequently used page navigation related events

Onnavigatedto

Triggered after navigating to the current page by another page

Onnavigatedfrom

Triggered after navigating to another page from the current page

Onnavigatingfrom

Fires from the current page before navigating to another page

Onbackkeypress

Triggered when the user presses the Back button on the phone, you can execute E in its event handler function. Cancel =true undo Back

2. Inter-page parameter passing

Windows phone parameters are passed in a way that is very similar to the web when the page jumps. Pass parameters in the URI of the jump. Gets the parameter through the navigationcontext.querystring["id" method in the target page, Similar to ASP. NET, but unlike ASP. The Get parameter program throws an exception when no arguments are passed, and ASP. NET gets the parameter null without reporting an exception. In the Windows Phone we can try to get the parameters through TryGetValue (). The syntax is as follows:

1 string "" ; 2 if (NavigationContext.QueryString.TryGetValue ("ID" out ID)) 3 textblock1.text = ID;

3. Page Jump Data Staging

When a user presses the back key to return to an app page and the app does not exit, the page object persists in the phone's memory and is not destroyed, so the user can still see all of the original data status. The user from the current other page navigation jump to the current page is different, although the page address is the same, but at this time the system for us to create a new page instance, before the Page object is released from memory, with all the data on the page is lost, but sometimes we need to save the original page of data, such as user registration, Users may jump to a new page to edit items such as provincial and municipal data more complex information, complete the jump back to the registration page, at this time we need to be on the page to jump off the registration pages of the existing form data. The solution is to skip the live data to the temporary store provided by Windows phone before jumping away from the page containing the user's editing data, and remove the turntable data recovery site from the temporary storage area after the page jumps back. The specific implementation code is as follows:

1  //rewrite Onnavigatedfrom2 protected Override voidOnnavigatedfrom (System.Windows.Navigation.NavigationEventArgs e)3 {4phoneappservice.state["myvalue"] = TextBox1.Text;//record the scene5     Base. Onnavigatedfrom (e); 6 }7 8 //rewrite onnavigatedto9 protected Override voidonnavigatedto (System.Windows.Navigation.NavigationEventArgs e)Ten { One     if(PhoneAppService.State.ContainsKey ("myvalue"))  A     { -     ObjectSomeobject; -     if(PhoneAppService.State.TryGetValue ("myvalue", outsomeobject))  theTextBox1.Text = Someobject.tostring ();//Recovery Site -      } -     Base. Onnavigatedto (e); - } +         
    • Comprehend by analogy

Jump between pages to save the navigation-related events of the field data listener, which is consistent with the logical deletion (tombstonling) process, but the tombstone listens to the control changed (for example, the textchanged of the text box) and the loaded event of the page. Because we are dealing with the user click on Start or back, when the user returns to the page, triggering the loaded event, considering that the user may leave this page at any time, so we listen to the user to modify the information while listening to the changed event to store data synchronously. As a result, we realize that page loading (load) and navigation (Onnavigateto) have similar functions, and when we come to a page whether it is a page loaded directly or a page that jumps from a hyperlink, the Onnavigateto and loaded events are triggered. There is a strict order between them, the first trigger is the Onnavigateto event, and then the loaded event is triggered.

"16.Windows Phone" 16.3 Multi-page program

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.