WPF window on closing

后端 未结 2 1839
南笙
南笙 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;
    
        }
    

提交回复
热议问题