Application = code + markup Reading Notes (1) -- a simple WPF Program

Source: Internet
Author: User
Tags visual studio 2010

My development environment is Windows 7 flagship edition +. NET Framework 4 + Visual Studio 2010. later articles will be based on this environment.

1. Create a New Visual C # windows empty project. In fact, there is no other purpose, just to figure out the Assembly on which WPF depends;

2. To build a simple WPF application, you must reference the Assembly presentationcore, presentationframework, system, system. XAML, windowsbase, and so on;

3. Add a "class" item to the project wpfappbycode, delete all the default code generated by the system in the file, and add the system and system. Windows namespaces. If you are not familiar with the system namespace, I will not explain it. System. the Windows namespace contains all the WPF categories, structures (struct), interfaces (interfce), delegates (delegate), and enumeration types (Enum ), of course, it also includes the application and window classes. Other WPF namespaces start with system. Windows, such as system. Windows. Controls, system. Windows. input, and system. Windows. Media. Only system. Windows. forms is an exception. It is mainly the namespace of windows. forms. Except system. windows. forms. the classes in the namespace integration are used to integrate windows. forms and WPF programs. windows. namespaces starting with forms belong to traditional windows. forms namespace.

Using system;
Using system. windows;

Namespace wpfappbycode
{
Class Program
{
[Stathread]
Public static void main ()
{
Window mMain = new window ();
MMain. Title = "scarecrow ";
MMain. Show ();
System. Windows. Application APP = new application ();
App. Run ();
}
}
}

4. After the above Code is compiled and run, you will find that a console window is also running. This is the setting from the compilation option. You can modify this compilation option in Project Properties> Application> output type: Change the output type to Windows application. I think the console window is quite useful in the development stage. You can use it to display some text information for debugging. If there are too many bugs in the program, you cannot even display the GUI window, or enter an indefinite loop. At this time, you only need to type ctrl + C in the console window to close the program easily. These are the benefits of the console window.

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.