The purpose of navigation is to enter another page from one page. Whether it is a pre-determined linear sequence (wizard), a hierarchical user driver (in most website forms), or a dynamically generated path, there are three main methods to achieve this: call the navigate method, use hyperlinks, and use navigation logs.
Navigate Method:
The navigation container supports the navigate method, which allows you to change the current page. You can use the target page example:
1 NavigateDemoPage nd=new NavigateDemoPage();
2 this.NavigationService.Navigate(nd);
1 NavigateDemoPage nd=new NavigateDemoPage();
2 this.NavigationService.Navigate(nd);
Or a URI pointing to the target page to call navigate:
this.NavigationService.Navigate(new Uri("NavigateDemoPage.xaml",UriKind.Relative));
this.NavigationService.Navigate(new Uri("NavigateDemoPage.xaml",UriKind.Relative));
The page specified by Uri can be a loose XAML file or a compiled resource, but the root element of the XAML file must be page. To navigate to an HTML page, you must use the navigate overload that can accept a URI parameter. For example:
This. navigationservice. navigate (New uri ("http://www.microsoft.com "));
this.NavigationService.Navigate(new Uri("http://www.microsoft.com"));
The navigation container also has two attributes, which are the same as the two methods of navigate. You can navigate to a page instance by setting the content attribute:
this.NavigationService.Content=NavigateDemoPage;
this.NavigationService.Content=NavigateDemoPage;
You can also set the source attribute to a URI for Navigation:
this.NavigationService.Source=new Uri("NavigateDemoPage",UriKind.Relative);
this.NavigationService.Source=new Uri("NavigateDemoPage",UriKind.Relative);
There is no other reason to use these two attributes to replace the navigate method!
Use hyperlink ):
This behavior is similar to a hyperlink in HTML. It enables you to embed a hyperlink element in a textblock. The content is automatically displayed as a clickable hyperlink. The target page is specified by the navigateuri attribute in hyperlink, similar to href in HTML:
<TextBlock>
Click <Hyperlink NavigateUri="NavigateDemoPage.xaml">here</Hyperlink>here to view more information.
</TextBlock>
<TextBlock>
Click <Hyperlink NavigateUri="NavigateDemoPage.xaml">here</Hyperlink>here to view more information.
</TextBlock>
This is only intended to provide simpler HTML-style links. Of course, the target page of the link is known in advance.
Hyperlink supports more complex functions, similar to hyperlinks in HTML. For example, you can navigate to a frame when multiple frames exist, you can set the targetname attribute of hyperlink to the name of the target frame. To navigate to a section of the page, you can add a # sign and a name after the URI, which indicates the name of any element on the target page.
Use navigation logs:
Each navigation container contains navigation logs that record the navigation history, which is similar to Web browsers. The navigation log provides the logic of backward and forward. It maintains two stacks internally, namely backward stack and forward stack. You can initialize the rollback and forward actions on your own, you can also call the Goback and goforward methods of the navigation container by programming.
Navigationwindow always has a navigation log, but the frame may not have its own navigation log, which depends on the attribute value of journalownership.
Similar to the Web Browser style, the backward and forward actions are controlled by navigation logs. But how can we implement the stop and refresh buttons?
To stop a processing navigation operation at any time, you can call the stoploading method of the navigation container. to refresh the page, you can call the refresh method in the navigation container, which has no parameters.
You can remove navigation logs by setting the removefromjournal attribute of page to true.
Navigation events:
Whether or not the navigation uses navigate, hyperlinks, or navigation logs, it is always executed asynchronously. Many events are triggered during navigation. They allow you to display rich UIS, or even cancel navigation.
Before navigationprogress is triggered, navigationprogress is periodically triggered. The event navigationstopped is not displayed here. If the navigation is canceled or an error occurs, this event is triggered, instead of loadcompleted events.
Note: When you navigate from one HTML page to another, the navigation event is not triggered.!