A WPF application is managed by the System.Windows.Application class
Second, creating a WPF Application
There are two ways to create a WPF application:
1, Visual Studio and Expression Blend the default way to start the application using App.xaml file definition
The contents of the App.xaml file are roughly as follows:
1: <Application x:Class="WpfApplicationLifeCycle.App"
2: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation& quot;
3: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4: StartupUri="Window1.xaml">
5: <Application.Resources>
6: </Application.Resources>
7: </Application>
Where StartupUri specifies the initiated WPF form
2, you can customize the class, define the main method implementation of the WPF application launch
Add a class to the project, the code for the class is as follows, and in the project options, set this class as the startup item.
1: using System;
2: using System.Windows;
3:
4: namespace WpfApplicationLifeCycle
5: {
6: public class MainClass
7: {
8: [STAThread]
9: static void Main()
10: {
11: // 定义Application对象
12: Application app = new Application();
13:
14: // 方法一:调用Run方法,参数为启动的窗体对象
15: Window2 win = new Window2();
16: app.Run (win);
17:
18: // 方法二:指定Application对象 的MainWindow属性为启动窗体,调用无参数的Run方法
19: //Window2 win = new Window2();
20: //app.MainWindow = win;
21: //win.Show(); // 此处必须有win.Show(),否则不能显示窗体
22: //app.Run();
23:
24: // 方法三:
25: //app.StartupUri = new Uri("Window2.xaml", UriKind.Relative);
26: //app.Run();
27: }
28: }
29: }