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...