MainWindow property still refers to the object that
represents the closed window. (Optionally, you can use code to reassign
the MainWindow property to point to a different window.)
OnMainWindowClose This is the traditional approach??”your application stays alive only as
long as the main window is open.
OnExplicitShutdown The application never ends (even if all the windows are closed) unless
you call Application.Shutdown(). This approach might make sense if
your application is a front end for a long-running background task or if
you just want to use more complex logic to decide when your application
should close (at which point you??™ll call the Application.Shutdown()
method).
For example, if you want to use the OnMainWindowClose approach and you??™re using the
Application.xaml file, you need to make this addition:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml" ShutdownMode="OnMainWindowClose"
>
CHAPTER 3 n THE APPLICATION 62
Alternatively, you can apply the same setting through your project properties. To do so,
double-click the My Project node in the Solution Explorer, choose the Application tab, and
choose an option for the Shutdown Mode setting.
Pages:
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175