Why does unloaded event of window do not fire in WPF?

后端 未结 3 495
滥情空心
滥情空心 2021-01-17 18:26

In my WPF application I have created a window and show it as a dialog by calling it by the method ShowDialog(). But when I close the window by Close() method the Unloaded ev

3条回答
  •  执念已碎
    2021-01-17 18:41

    That's a known issue.

    Use this instead

       yourWindow.Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;
    
       private void Dispatcher_ShutdownStarted( object sender, EventArgs e )
       {
           //do what you want to do on closing
       }
    

    Read this for more details

    Edit

    If above is not working try this

    yourWindow.Closing += new CancelEventHandler(YourWindow_Closing);
    
    void YourWindow_Closing(object sender, CancelEventArgs e)
    {
    
    }
    

提交回复
热议问题