Original: Use of application.current in WPF
The WPF program corresponds to a Application object, the current application object can be obtained through application.current, and by acquiring the Application object, we can do the following things:
Application.Current.FindResource ("Resource Name");//get the resources defined in the programApplication.Current.MainWindow;//get the main form defined in the programapplication.current.properties["MyProperty"];//Gets or sets the applied scope propertiesApplication.Current.Shutdown ();//Terminate Current ProgramApplication.Current.ShutdownMode = Shutdownmode.onlastwindowclose;//set how programs are closed//onlastwindowclose--Closing a program when the last form is closed//onmainwindowclose--Closing a program when the main form is closed//onexplicitshutdown--need to show call Application.Current.Shutdown () to close the program, or the program will continue to run in the backgroundApplication.Current.Windows;//get all forms running in the program//The General main window experience is the first running form, so at this point application.current.windows[0] is equivalent to Application.Current.MainWindow
Use of application.current in WPF