How to override onclose event on WPF?

前端 未结 2 1284
花落未央
花落未央 2020-12-20 17:15

I\'m trying to override the onclose event on WPF, this is my code so far:

protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
               


        
相关标签:
2条回答
  • 2020-12-20 17:50

    You are asking it not to close by setting e.Cancel = true. Just don't do that.

    0 讨论(0)
  • 2020-12-20 17:58

    The application never closes because you are setting e.Cancel to true.

    Try

    protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
    {
           //do my stuff before closing
    
           base.OnClosing(e);       
    }
    
    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题