When started in this way, your application continues running until the main window and
every other window is closed. At that point, the Run() method returns, and any additional code
in your Main() method is executed before the application winds down.
nNote If you want to start your application using a Main() method, you need to designate the class that
contains the Main() method as the startup object in Visual Studio. To do so, double-click the My Project node
in the Solution Explorer. In the Application tab, remove the check mark next to the Enable Application Framework
setting. You can then choose Sub Main in the Startup Object list. Ordinarily, you don??™t need to take this
step, because Visual Studio creates the Main() method for you based on the XAML application template.
You??™ll learn about the application template in the next section.
Deriving a Custom Application Class
Although the approach shown in the previous section (instantiating the base Application class
and calling the Run() method) works perfectly well, it??™s not the pattern that Visual Studio uses
when you create a new WPF application.
Instead, Visual Studio derives a custom class from the Application class. In a simple application,
this approach has no meaningful effect. However, if you??™re planning to handle
application events, it provides a neater model, because you can place all your event handling
code in the Application-derived class.
Pages:
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171