如何覆盖WPF上的onclose事件?

Hom*_*osa 8 c# wpf

我试图覆盖WPF上的onclose事件,这是我的代码到目前为止:

protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
       base.OnClosing(e);
       e.Cancel = true;
       //do my stuff before closing
}
Run Code Online (Sandbox Code Playgroud)

它执行代码但应用程序永远不会关闭.任何想法如何解决这一问题?

Bal*_*a R 16

该应用程序永远不会关闭,因为你设置e.Canceltrue.

尝试

protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
       //do my stuff before closing

       base.OnClosing(e);       
}
Run Code Online (Sandbox Code Playgroud)


Ric*_*key 6

你问它不要通过设置关闭e.Cancel = true.只是不要这样做.