Element. Unloaded Event
当从加载的元素的元素树中移除元素时发生。Occurs when the element is removed from within an element tree of loaded elements.
public: event System::Windows::RoutedEventHandler ^ Unloaded;
public event System.Windows.RoutedEventHandler Unloaded;
member this.Unloaded : System.Windows.RoutedEventHandler
Public Custom Event Unloaded As RoutedEventHandler
直接路由事件不遵循路由，它们只能在引发它们的同一元素内进行处理。Direct routed events do not follow a route, they are only handled within the same element on which they are raised. 直接路由事件支持其他路由事件行为：它们支持可访问的处理程序集合，并且可用作样式中的 EventTrigger。Direct routed events do support other routed event behavior: they support an accessible handlers collection, and can be used as an EventTrigger in a style.
由于用户启动的系统主题更改，Loaded 和 Unloaded 可能会在控件上引发。Loaded and Unloaded might both be raised on controls as a result of user-initiated system theme changes. 主题更改会导致控件模板和包含的可视化树失效，这进而导致整个控件被卸载和重新加载。A theme change causes an invalidation of the control template and the contained visual tree, which in turn causes the entire control to unload and reload. 因此，不能假定 Unloaded 仅在离开页面时才会发生。Therefore Unloaded cannot be assumed to occur only on navigation away from the page.
请注意，在应用程序开始关闭后，不会引发 Unloaded 事件。Note that the Unloaded event is not raised after an application begins shutting down. 当发生由 ShutdownMode 属性定义的条件时，将发生应用程序关闭。Application shutdown occurs when the condition defined by the ShutdownMode property occurs. 如果将清理代码放在 Unloaded 事件的处理程序中（例如 Window 或 UserControl），则可能无法按预期方式调用。If you place cleanup code within a handler for the Unloaded event, such as for a Window or a UserControl, it may not be called as expected.
路由事件信息Routed Event Information