且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

关闭WPF窗口但不关闭应用程序

更新时间:2022-10-24 20:20:12

如果设置 e.Cancel = true; 你要求程序不要通过取消结束活动来关闭。

因此你的窗口仍然保持打开状态。



你可以最小化到任务管理器或通知托盘 [ ^ ]。

Hi, i wan''t to close a wpf window but i don''t want to close the entire application. I try to override OnClosing method:

protected override void OnClosing(CancelEventArgs e)
{
    base.OnClosing(e);
    e.Cancel = true;
}



but when I press close button the window remains on the screen.

Can you help me please!!

If you set e.Cancel = true; you are asking the program not to close by cancelling the closing event.
Thus your window still remains open.

You can minimize to the task manager or to the notification tray[^].