WPF window on closing

后端 未结 2 1838
南笙
南笙 2021-01-23 03:26

I want send some data on server, before window close. I use event closing, but it doesn t wokr. Where is a problem?

    private void Window_Closing(object sender         


        
相关标签:
2条回答
  • 2021-01-23 04:06

    Try overriding OnClosing in the window code behind. There you have a chance to stop the window from closing if you have something else to do by setting e.Cancel = true.

        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
           bool isClosed = _obj.CloseConnection();
    
           if(!isClosed)
              e.Cancel = true;
    
        }
    
    0 讨论(0)
  • 2021-01-23 04:08

    Did you check if there's a problem on _obj.CloseConnection()? Try to debug your code and check if the event handler is called.

    0 讨论(0)
提交回复
热议问题