You can set shutdownmode:onlastwindowclose in App.xaml (at which point you can change the Application.mainwindow property and reference other Windows) Onmainwindowclose Onexplicitshutdown (explicitly called Application.shutdown ()).
Calling the Application.shutdown () method causes the Application.Run () method to return immediately, but you can still run the other code in the main () method and handle the Application.exit event.
Common events for the application class, Startup Exit sessionending Activated Deactivated dispatcherunhandledexception, as follows:
<x:class= "Wpfapplication2.app" xmlns= "http// Schemas.microsoft.com/winfx/2006/xaml/presentation " xmlns:x="/http/ Schemas.microsoft.com/winfx/2006/xaml " xmlns:local=" Clr-namespace:wpfapplication2 " StartupUri= "MainWindow.xaml" dispatcherunhandledexception= " Application_dispatcherunhandledexception ">
You can override the On+ event name in the application class to trigger an event, such as
/// <summary> /// the interactive logic of App.xaml /// </summary> Public Partial class app:application { protectedoverridevoid onstartup (StartupEventArgs e) { Base . Onstartup (e); } }
Gets the instance of the current application application.current
Use the application class to achieve communication and management between different windows.
Implementation of a single-instance application.
Application classes in WPF