C # WPF vs winform

Source: Internet
Author: User

WPFI have heard of WPF, a famous name for WCF, but I have never known her ...... Today, I suddenly want to see what she looks like?

It is mainly to leave a note for yourself. By the way, we can compare the differences between WPF and winform.

1. What is WPF? What is the purpose?

Definition: Windows Presentation Foundation (WPF ){ [, Prez limit n'tei limit N, PRI:-] N. Description, statement; introduction; present,[Faun' dei limit N] N. Foundation; Creation } Yes MicrosoftThe Windows Vista-based user interface framework is part of. NET Framework 3.0. It provides a unified programming model, language, and framework that truly isolates the work of the interface designers and developers. It also provides a new graphic interface for multimedia interaction.

Purpose: Take a look at the official website or go to the encyclopedia.

Eg:

BackgroundCode

 /*  ** Chapter 2 Windows Presentation Foundation *  */  Using  System;  Using System. Collections. Generic;  Using  System. LINQ;  Using  System. text;  Using  System. windows;  Using  System. Windows. controls;  //  AddProgramSet windowsbase, presentationcore, and presentationframework references  Namespace  _ 5leleapplication1 {  Class Program {  //  Stathread: single thread apartment thread. (single thread unit thread)  //  [] Is used to indicate attributes;  //  It is a thread model used in the program's entry method (in C # and VB. NET, it is the main () method) to specify that the apartmentstate of the current thread is Sta. It does not affect other methods. On the ASPX page, you can use aspcompat = "true" to achieve the same effect. This attribute is only useful in COM InterOP, and useless if all are managed code. [Stathread] indicates that the default thread model of an application is a single-threaded unit (STA ). The startup thread model can be set to single-threaded or multi-threaded. If it is not set, the thread is not initialized. That is to say, if you use the. NET Framework and do not use com InterOP, you generally do not need this attribute. Others include MTA (multi-thread suite) and free thread (free thread)  [Stathread]  Static  Void Main ( String  [] ARGs) {window mainwindow = New  Window (); canvas = New Canvas (); //  ['K running NV ə S] n. Canvas vt. Covered with canvas, equipped with canvas Mainwindow. content = Canvas; mainwindow. Title = "  WPF Application  " ; Button button1 = New  Button (); canvas. Children. Add (button1 );  //  The WPF element can also obtain features from the parent element. For example, if the button element is in the canvas element  //  And left attributes use the parent element name as the prefix. This property is called an attached property: Canvas. setleft (button1, 140  ); Canvas. settop (button1,  130  ); Button1.content = " Click me!  "  ;  //  Mainwindow. content = button1; Button1.click + = (sender, e) => MessageBox. Show ( "  Button clicked  "  ); Application app = New Application (); //  The run () method of the application class is responsible for processing Windows messages.  App. Run (mainwindow );}}} 

Running result:

I can't tell the difference between winform and winform ......

 

 

Paste another front-end code

<Window X: class = "  _ 6wpfapplication1. window1  "  Xmlns = "  Http://schemas.microsoft.com/winfx/2006/xaml/presentation  "  Xmlns: x = "  Http://schemas.microsoft.com/winfx/2006/xaml  " Title = "  Window1  " Height = "  300  " Width = "  300  " > <Grid> </GRID> </WINDOW>

 

 

 

2. Let's take a look at the code to summarize the following differences:

1. A major feature of WPF is that the work of designers and developers is easily separated. The results of the design work can be directly used by developers. Designers can use the expression blend tool, while developers use Visual Studio 2008 [prerequisite is that you must understand XAML]

XAML: XML for applications Markup Language (XAML) is used to define the hierarchy of user interfaces.

2. WPF programming is very similar to window form programming. The difference is that the button has the content attribute instead of the text attribute.

3. namespace:

The Windows form class is located in the system. Windows. Forms namespace.

The WPF class is located in the system. Windows namespace and its sub-namespace.

 

4. Windows Forms controls are based on Windows built-in controls and use Windows handles based on screen pixels. While WPF is based on DirectX. Applications no longer use Windows handles, making it easier to reset the UI size and built-in support for audio and video.

 

5. WPF and winform: radish and vegetables each have their own love

 

The revolution has not yet succeeded. If you want to learn more, you have to continue reading books and exercises. Here I am only recording my study notes... Wish you success

 

<Window X: class = "  _ 6wpfapplication1. window1  "  Xmlns = "  Http://schemas.microsoft.com/winfx/2006/xaml/presentation  "  Xmlns: x = "  Http://schemas.microsoft.com/winfx/2006/xaml  "  Title = "  Continue to advance if you want to learn something.  " Height = "  300  " Width = "  300  " > <Canvas> <ellipse canvas. Left = "  50  " Canvas. Top = "  50  " Width ="  100  " Height = "  100  "  Stroke = "  Blue  " Strokethickness = "  4  " Fill = "  Yellow  " /> <Ellipse canvas. Left = "  60  " Canvas. Top = "  65  " Width = "  25  " Height = "  25  "  Stroke = "  Blue " Strokethickness = "  3  " Fill = "  White  " /> <Ellipse canvas. Left = "  70  " Canvas. Top = "  75  " Width = "  5  " Height = "  5  "  Fill = "  Black  " /> <Path stroke = "  Blue  " Strokethickness = "  4  " Data = "  M 62,125 Q 95,122             102 , 108  "  /> <Line X1 = "  124  " X2 = "  132  " Y1 = "  144  " Y2 = "  166  " Stroke ="  Blue  "  Strokethickness = "  4  " /> <Line X1 = "  114  " X2 = "  133  " Y1 = "  169  " Y2 ="  166  " Stroke = "  Blue  "  Strokethickness = "  4  " /> <Line X1 = "  92  " X2 = "  82  " Y1 ="  146  " Y2 = "  168  " Stroke = "  Blue  "  Strokethickness = "  4  " /> <Line X1 = "  68  " X2 ="  83  " Y1 = "  160  " Y2 = "  168  " Stroke = "  Blue  "  Strokethickness = "  4  " /> </Canvas> </WINDOW>

 

Related Article

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.