When your application is launched, you??™ll create the old-style application class, which
will then create the WPF application class. The old-style application class handles the instance
management, while the WPF application class handles the real application. Figure 3-2 shows
how these parts interact.
Figure 3-2.Wrapping the WPF application with a WindowsFormsApplicationBase
The first step to use this approach is to derive a custom class from the
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase class. This
class provides three important members that you use for instance management:
??? The IsSingleInstance property enables a single-instance application. You set this
property to True in the constructor.
??? The OnStartup() method is triggered when the application starts. You override this
method and create the WPF application object at this point.
CHAPTER 3 n THE APPLICATION 70
nNote Ordinarily, all applications that derive from WindowsFormsApplicationBase designate a main form.
However, your application uses the WPF model, so it won??™t include any forms. To prevent an error, you must
replace the default startup logic by overriding OnStartup(). It??™s not enough to simply handle the Startup event.
??? The StartupNextInstance event is fired when another instance of the application starts
up.
Pages:
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188