Unloaded Event
Collapse the table of content
Expand the table of content

FrameworkElement.Unloaded Event

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Occurs when this object is no longer connected to the main object tree.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public event RoutedEventHandler Unloaded
<frameworkElement Unloaded="eventhandler"/>

Use a handler based on RoutedEventHandler to handle this event.

When an object is removed from the main object tree, it is no longer displayed in Windows Phone UI. This can be an appropriate time to remove references that the object makes to other resources. For example, connections that the object makes to Web services might currently be closed.

Unloaded is raised asynchronously versus the object tree change.

Despite being raised asynchronously, the order in which Unloaded events are raised from within a contiguous subtree of objects is consistent. Unloaded events are raised top-down and in the order of placement of peer objects in the run time object tree. The top or root of the subtree raises the first Unloaded event. The first child element of the root raises the next Unloaded event, and then any children and so on. After returning to any level of the object tree where there are peers that have not yet raised the event, that branch's subroot raises Unloaded and is traversed, and so on.

Although the event data uses RoutedEventArgs, Unloaded is not a routed event in Windows Phone.

Unloaded is not raised for any object if the Windows Phone application shuts down for any reason.

Objects that are being reparented but still remain in the main object tree in the end representation will raise Unloaded and then Loaded. This is the case for all objects in a subtree, if a subtree is reparented.

Visibility being set to Visibility.Collapsed is not equivalent to being unloaded from the object tree, and does not raise Unloaded on an object. Similarly, changing the open state of a Popup does not raise Unloaded on the Popup or any of its child elements.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft