WPF and Silverlight Learning notes (v): WPF Application Management

Source: Internet
Author: User
Tags xmlns silverlight visual studio

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: }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.