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.