Execution sequence and difference of several page events on Windows Phone

Source: Internet
Author: User

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.

 

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.