There are three shutdown Modes
Member name |
Description |
Onlastwindowclose |
An application shuts down when either the last window closes, or shutdown is called. |
Onmainwindowclose |
An application shuts down when either the main window closes, or shutdown is called. |
Onexplicitshutdown |
An application shuts down only when shutdown is called. |
Onmainwindowclose is useful, but you must first know how to specify mainwindow.
Two ways to specify mainwindow:
1. InCodeSpecified in
/// <Summary>
/// Interaction logic for app. XAML
/// </Summary>
Public APP ()
{
Window oldmainwindow = This . Mainwindow; // Get Main Window
Window newmainwindow = New Window1 ();
This . Mainwindow = New Window (); // Set mainwindow
}
2. Specify
< Application
Xmlns = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "Http://schemas.microsoft.com/winfx/2006/xaml"
Startupuri = "Startupwindow. XAML"
>
< Application. mainwindow >
< Navigationwindow Source = "Mainpage. XAML" Visibility = "Visible" > </ Navigationwindow >
</ Application. mainwindow >
</ Application >
Configure shutdown mode
Here we select onmainwindowclose:
< Application X: Class = "Testapplication. app"
Xmlns = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation%22
Xmlns: x =" Http://schemas.microsoft.com/winfx/2006/xaml%22
Startupuri = "Window1.xaml"
Shutdownmode = "Onmainwindowclose"
>
</ Application >