Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.unloaded.aspx" rel="noreferrer">documentation</a>:</p> <p>"Note that the Unloaded event is not raised after an application begins shutting down. Application shutdown occurs when the condition defined by the ShutdownMode property occurs. 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."</p> <p>If closing your Window triggers your application's shutdown, that might be the cause. In that case, even the Window's Unload event might not be called as well, so I believe it's better to rely on the <a href="http://msdn.microsoft.com/en-us/library/system.windows.window.closing.aspx" rel="noreferrer">Window.Closing</a> event. </p> <p>One approach to handle the tasks your UserControl does when unloaded is to expose the unload handler method of the control ("DBLoginUserFrame_Unloaded"), name your UserControl instance in the MainWindow and call it from the Window.Closing event.</p> <pre><code>public MainWindow() { // Add this this.Closing += MainWindow_Closing; } void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { this.MyUserControl.MethodToBeCalledWhenUnloaded(). } </code></pre> <p>Another option is to keep your implementation so far but also add in your UserControl a handler for the Dispatcher.ShutdownStarted event, as described <a href="http://geekswithblogs.net/cskardon/archive/2008/06/23/dispose-of-a-wpf-usercontrol-ish.aspx" rel="noreferrer">here</a>.</p> <pre><code>public MyUserControl() { this.Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload