WPF App Doesn't Shut Down When Closing Main Window

后端 未结 6 1725
滥情空心
滥情空心 2020-12-01 02:22

I\'m used to WinForms programming in Visual Studio, but I wanted to give WPF a try.

I added another window to my project, called Window01. The main window is called

6条回答
  •  Happy的楠姐
    2020-12-01 03:18

    Because the default shutdown mode in a WPF application is OnLastWindowClose, which means the application stops when the last window closes.

    When you instantiate a new Window object, it automatically gets added to the list of windows in the application. So, the problem was that your application was creating two windows when it started - the MainWindow and the not-yet-shown Window01 - and if you only closed the MainWindow, the Window01 would keep your application running.

    Normally, you will create a window object in the same method that is going to call its ShowDialog, and you will create a new window object each time the dialog is shown.

提交回复
热议问题