The event trigger sequence is
Enter the page: onnavigatedto (the control has not been loaded)-> loaded (the control has been loaded)
Exit page: onnavigatingfrom (the page control still exists)-> onnavigatedfrom (the page control still exists)
-> Unloaded (enter the second page after execution)
(1) onnavigatedto method: called when the page changes to an activity page in the framework.
Generally, the onnavigatedto event is rewritten to check the Navigation Request and prepare the page to be displayed. For examplePrepare the data loaded by related requests. Generally, the onnavigatedto method is used.Instead of using the loaded event processing function. It is best to use the onnavigatedto method, because this method is called only once every time the page becomes an active page. The Silverlight framework triggersLoaded event. This event may occur multiple times when a page is activated..
The onnavigatedto method is called for each request, even when the page is retrieved from the cache. We should include the code that must be executed for each request in this method, rather than placing the code that must be executed in the page constructor.
(2) loaded event: When a frameworkelement has been constructed and added to the object tree, this event is triggered when the page is loaded. Most controls have this event, which is triggered after the control is loaded. This event is not routed (while many Silverlight input events are routed ). Note: The child control first loaded and then the parent control loaded.
(3) onnavigatingfrom: called just before the page is no longer an active page in the framework.
If you want to perform an operation before the page changes to inactive, You can override the onnavigatingfrom method. For example, save the data on the current page.
(4) onnavigatedfrom: called when a page is no longer an active page in the framework.
If we need to perform the final operation when the page becomes inactive, We can reload the onnavigatedfrom operation. For example, Update page-related data.
(5) unloaded: This occurs when the object is no longer connected to the main object tree.
Similar to the loaded event, unloaded is not a routing event in Silverlight. If the Silverlight application is closed for any reason, no object will trigger the unloaded event. In contrast to the loaded event, the parent control first unloaded and then the child control unloaded.
Note: The visibility set to visibility. collapsed is not equivalent to being detached from the object tree and does not cause unloaded on the object. Similarly, changing the open status of popup does not cause unloaded on popup or any child element.