Windows Phone Development (8): Tips on navigating

Source: Internet
Author: User

The previous article with a few examples of navigation to do a brief introduction, in general applications, using the method mentioned in the previous articles, in fact, enough, but, in order to be able to deal with some special situations, there are a few tips or need to know.

First, in the end should not set the "back" operation?
Because there is a "fallback" button on the hardware layer of the phone, we do not need to add any fallback buttons to the program, but it is still necessary to see how to add the fallback function manually.

1, a new WP application project.
2. Create a new page Page2.xaml, in addition to the default homepage.
3. Put a button on the home page, write the Click event handling code, and navigate to Page2.

    1. private void Button1_Click (object sender, RoutedEventArgs e)
    2. {
    3. This. Navigationservice.navigate (New Uri ("/page2.xaml", urikind.relative));
    4. }


4, put a button in Page2, and write the click event handling code. 4, put a button in Page2, and write the click event handling code. 4, put a button in Page2, and write the click event handling code.

    1. private void Button1_Click (object sender, RoutedEventArgs e)
    2. {
    3. This. Navigationservice.goback ();
    4. }


5. Now, you can enjoy your program.

Second, how to block out the "fallback" button?
Rarely in this case, blocking the fallback button means that you cannot navigate backwards by pressing "fallback", which is an exercise to use with caution.
To do this, you have to handle the Backkeypress event and set the Cancel property of the event argument E to True to cancel the "fallback" key operation.
    1. This. backkeypress + = (sender, e) = =
    2. {
    3. E.cancel = true;
    4. };

Third, how to delete navigation history?
For example, I am now navigating to page b from the main page and navigating to page C from page B, but I do not want the user to navigate back to page B, but instead navigate back to the home page.

Prepare three pages for the test, navigate from the homepage to B, navigate from B to C, it should be okay, no need to repeat.

Then, since we are now going to remove page B from the fallback history of the navigation, we delete the history after leaving page B. In other words, override the Onnavigatedfrom method in page B.

  1. protected override void Onnavigatedfrom (System.Windows.Navigation.NavigationEventArgs e)
  2. {
  3. Base. Onnavigatedfrom (e);
  4. Phoneapplicationframe myframe = Application.Current.RootVisual as Phoneapplicationframe;
  5. if (myframe! = null)
  6. {
  7. Try
  8. {
  9. Myframe.removebackentry ();
  10. }
  11. catch (InvalidOperationException ex)
  12. {
  13. MessageBox.Show (ex. Message);
  14. }
  15. }
  16. }


As seen from the example, use the Removebackentry method of the Phoneapplicationframe class to delete the latest record, delete only one at a time, to delete multiple, call n times. Because the navigation history is a stack structure, LIFO, so, like you put a bunch of books on the desktop, the first to take off is placed on the top, as shown in: From the example, see, Use the Removebackentry method of the Phoneapplicationframe class to delete the latest record, delete only one at a time, to delete multiple bars, call n times. Because the navigation history is a stack structure, LIFO, so, like you put a bunch of books on the desktop, the first to take off is placed on the top, as shown in:

Windows Phone Development (8): Tips on navigating

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.