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.
- private void Button1_Click (object sender, RoutedEventArgs e)
- {
- This. Navigationservice.navigate (New Uri ("/page2.xaml", urikind.relative));
- }
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.
- private void Button1_Click (object sender, RoutedEventArgs e)
- {
- This. Navigationservice.goback ();
- }
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.
- This. backkeypress + = (sender, e) = =
- {
- E.cancel = true;
- };
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.
- protected override void Onnavigatedfrom (System.Windows.Navigation.NavigationEventArgs e)
- {
- Base. Onnavigatedfrom (e);
- Phoneapplicationframe myframe = Application.Current.RootVisual as Phoneapplicationframe;
- if (myframe! = null)
- {
- Try
- {
- Myframe.removebackentry ();
- }
- catch (InvalidOperationException ex)
- {
- MessageBox.Show (ex. Message);
- }
- }
- }
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