Application class is the most important class responsible for managing the application level functionality.The life cycle of WPF application is managed by the Application class.
It manages functionality such as setting which window is currently active in the application,handling unhanded exceptions and defining resources to be shared across the application.
A running WPF application consists of a single object of Application class.It raises different events when the WPF application is executing.
- Run method starts the application
- After the Run method is called it fires the StartUp event.This indicates that the application is starting.
- Activated is raised when the application starts executing
- Deactivated is raised when the application goes to background.
You can implement the following methods in your application class to handle the above events:
You implement these methods in the code behind of your app.xaml file
public partial class App : Application
private void OnStartup(StartupEventArgs)(object sender, StartupEventArgs e)
private void OnActivated(object sender, StartupEventArgs e)
It also provides the Run() method which starts the application
You define application resources using the XAML of the application class as:
The resources which you define in the XAML of the application class can be accessed across the entire application.