Use the Application class to get windows through Application.Windows -property exactly as you described. If you are in window code, call this.Close();
Configuration for multiple Windows
Set the main window to the Application.MainWindow property and set Application.ShutdownMode to the appropriate value if you also want to open the application if the main window is closed (for example, App.Current.ShutdownMode=ShutdownMode.OnExplicitShutdown; ).
I already noticed that some people had problems with ShutdownMode. The workaround for this is to open the first invisible window, and from this window you will open the visible application windows. This prevents the application from closing if the first window created is closed. However, you must also solve this problem over the ShutdownMode property.
In multi-window scenarios, you can use Shutdown to close the application without closing each window.
Hope this answer will be your question. Make a comment if not.
source share