WPF Application Events
You can handle the following WPF Application events by creating handlers for the events in your WPF project's MainEntry.Main() method. You can reference the Application object by using the appWrapper.Application property. To see an example, in MainEntry.Main() the DispatcherUnhandledException event is already handled for you.
| Event Name | Description |
|---|---|
| Startup | Raised after Application.Run() is called but before the main window is displayed. You can use the StartupEventArgs.Args property to check any arguments that have been passed to the application |
| Exit | Raised when the application is being shut down just before the Run() method returns. The ExitEventArgs.ApplicationExitCode property allows you to examine the integer value the app returns to Windows |
| SessionEnding | Raised when the Windows session is ending. The SessionEndingCancelEventArgs.ReasonSessionEnding property gives you the reason. Setting Cancel to true stops the session from ending |
| Activated | Raised when a user switches to your app from another Windows app, as well as when you first display a window |
| Deactivated | Raised when a user switches to a different Windows app. |
| DispatcherUnhandledException | Raised when an unhandled exception orrucs in the application. This event is already handled in MM .NET and is used to record exceptions in the Application Log. |
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 10/23/10
Comment or report problem with topic
