Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF closing all windows when user closes one of them

Tags:

wpf

There's a WPF application with multiple windows. Initially there's only one window. User may go to next windows while previous are hidden. When they return back, hidden windows appear again. The problem is that when user closes some window, the hidden ones continue to run as processes. Is it possible to close all of them when user closes any.

like image 580
Sergey Avatar asked Aug 08 '11 12:08

Sergey


People also ask

How do I close all windows in WPF?

The proper way to shutdown a WPF app is to use Application. Current. Shutdown() . This will close all open Window s, raise some events so that cleanup code can be run, and it can't be canceled.

Is WPF still relevant 2021?

WPF is still one of the most used app frameworks in use on Windows (right behind WinForms).

Which method is invoked when the user attempts to close the window from the window's system menu?

The Window. close() method closes the current window, or the window on which it was called. This method can only be called on windows that were opened by a script using the Window.

Is WPF front end or backend?

WPF uses XAML as its frontend language and C# as its backend languages. WPF was introduced as a part of . NET Framework 3.0 as the Windows library to build Windows client apps and the next generation of Windows Forms.


1 Answers

If you want to terminate an application with all windows, you can call App.Current.Shutdown();. If you want call this on closing of any window, register to the Window.Closed event and call App.Current.Shutdown(); there in.

Through App.Current.Windows you have access to all Window-instances. You also can close them manually.

like image 83
HCL Avatar answered Oct 12 '22 13:10

HCL