WPF learning path (9) Navigation and page (continued); wpf path

Source: Internet
Author: User

WPF learning path (9) Navigation and page (continued); wpf path

Lifecycle

If Page1 is successfully navigated to Page2, The NavigationService Navigating event is triggered first to identify the start of the navigation. Create a Page2 object and trigger the NavigationProgress event. This event is used to provide navigation progress information. This event is triggered every time 1 kb of data is returned. Then the Navigated event is triggered, followed by LoadCompleted, indicating that the page has been downloaded. Page1 triggers the UnLoaded event and ends the event. Page2 triggers the Loaded event, indicating that it starts.

 

Example (from "sunflower collection-WPF manual")

App. xaml

<Application x:Class="Alex_WPFAPPDemo07.App"             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"             Navigating="Application_Navigating"              NavigationFailed="Application_NavigationFailed"              Navigated="Application_Navigated"              NavigationProgress="Application_NavigationProgress"              NavigationStopped="Application_NavigationStopped"              LoadCompleted="Application_LoadCompleted"              FragmentNavigation="Application_FragmentNavigation"              StartupUri="CustomPage.xaml">    <Application.Resources>        <Style TargetType="TextBlock">            <Setter Property="FontSize" Value="15" />            <Setter Property="Margin" Value="5" />        </Style>    </Application.Resources></Application>

App. xaml. cs

Public partial class App: Application {private void Application_Navigating (object sender, System. windows. navigation. navigatingCancelEventArgs e) {System. console. writeLine ("----------------------------------------"); System. console. write ("triggered event: Application_Navigating \ n"); System. console. writeLine ("Uri on the navigation page:" + e. uri. toString ();} private void Application_NavigationFailed (object sender, System. windows. navigation. navigationFailedEventArgs e) {System. console. writeLine ("----------------------------------------"); System. console. write ("triggered event: Application_NavigationFailed \ n"); System. console. writeLine ("failed exception:" + e. exception. toString (); // set the Handled property to true to prevent the upload from being changed to an unprocessed application exception. handled = true;} private void Application_Navigated (object sender, System. windows. navigation. navigationEventArgs e) {System. console. writeLine ("----------------------------------------"); System. console. write ("triggered event: Application_Navigated \ n"); System. console. writeLine ("Uri on the navigation page:" + e. uri. toString ();} private void Application_NavigationProgress (object sender, System. windows. navigation. navigationProgressEventArgs e) {System. console. writeLine ("----------------------------------------"); System. console. write ("triggered event: Application_NavigationProgress \ n"); System. console. writeLine ("Uri on the navigation page:" + e. uri. toString (); System. console. writeLine ("the number of bytes obtained is {0}", e. bytesRead);} private void Application_NavigationStopped (object sender, System. windows. navigation. navigationEventArgs e) {System. console. writeLine ("----------------------------------------"); System. console. write ("triggered event: Application_NavigationStopped \ n"); System. console. writeLine ("Uri on the navigation page:" + e. uri. toString ();} private void Application_LoadCompleted (object sender, System. windows. navigation. navigationEventArgs e) {System. console. writeLine ("----------------------------------------"); System. console. write ("triggered event: Application_LoadCompleted \ n"); System. console. writeLine ("Uri on the navigation page:" + e. uri. toString ();} private void Application_FragmentNavigation (object sender, System. windows. navigation. fragmentNavigationEventArgs e) {System. console. writeLine ("----------------------------------------"); System. console. write ("triggered event: Application_FragmentNavigation \ n"); System. console. writeLine ("the navigation section is:" + e. fragment );}}

Modify the Output type attribute of a project

 

Results:

 

In the console output, you can see which events have been processed during the navigation process.

 

 

 

 

 

 

 

 

To be continue...

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.