c# - 如何覆盖 WPF 上的 onclose 事件?

标签 c# wpf

我正在尝试覆盖 WPF 上的 onclose 事件,这是我目前的代码:

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

它执行代码但应用程序永远不会关闭。有什么解决办法吗?

最佳答案

应用程序永远不会关闭,因为您将 e.Cancel 设置为 true

尝试

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

       base.OnClosing(e);       
}

关于c# - 如何覆盖 WPF 上的 onclose 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5774849/

相关文章:

c# - 将 Between 和其他函数作为 LINQ 表达式实现

c# - 在每次绘制时重绘不变的背景?

c# - WPF DataGrid Cell 不离开编辑模式

c# - 如果我在 NET Core 库中添加 PackageReference net46 会怎样?

c# - 如何调用 FastEqualsCheck()?

c# - WPF 强制用户停留在 TabItem 上

c# - 为什么 UTF8Encoding.GetBytes 不发出字节顺序标记?

wpf - WPF MVVM并将 View 模型传递给 View

c# - 我可以将数据从 Winforms 传递到 WPF 控件吗?

wpf - Textblock 中的标签自动换行不起作用