One of WPF learning and sharing: Comparison between WPF and winform

Source: Internet
Author: User

Recently, I want to start learning.WPF, Read some information, and write down your learning experience, hoping to help you.

WPFDeveloped onWinformFrom the perspective of technological development,WPFRatioWinformAdvanced is beyond doubt. I thinkWPFComparedWinformIt has the following good features:

Solution Window handle Problem

in Windows GDI or winform complex GUI the application Program uses a large number of controls, for example, grid . Each widget or grid cell is a small window, A window handle is used, although the control vendor provides many optimization methods, however, we still encounter out of memory or " error create window handle ", causing the program to exit.

WPFThe display mode of the control is completely changed, and the control will not be occupied if it is not in the window.Window handle. Theoretically, ifWPFIf there is only one main window,WPFOnly oneWindow handle(If ignoredDispatcher). SoWPF GuiThe program does not appearWindow handleInsufficient.

Multi-thread processing

InWinformOne of the biggest headaches during program development is that,WorkerThe program crashes because the thread modifies the properties of the control, and this illegal operation does not fail every time.WinformControls provideInvokerequiredAttribute to determine whether the current thread is a control creation thread. The problem is that when the control tree is deep, this attribute will be slow.

WPFAt the beginning of the design, the problem of multithreading was taken into account. MostWPFClasses are inherited fromDispatcherobject.DispatcherobjectActuallyDispatcherIs a simple encapsulation.DispatcherProvidesInvokerequiredMethod(Checkaccess). This method is only thread-specific.ID, So it will soon. In addition,DispatcherProvides priority queues and asynchronous calls,TimerFeatures suchGuiProgram.

Control Composition

InWinformIf you want to implementCheckboxThe drop-down menu of will have to deal with complicatedWindowMessage. And passWPFControlContent ModelAndLayoutSystem,WPFControls can include any type of controls, or even. Net CLRObject. Many modern control manufacturers also provideCompositionControls, implementation methods andWPFOfContentThe model is also similar.WPFThe development team should learn from it.Infragistics. With this foundation, the development of newWPFControls are simpler.

XAML

I personally think that XAML should be an epoch concept in WPF. With XAML, we can describe complex object graphs in text mode. This idea is available in VB, but XAML is simpler to use tools to generate XAML. Through command, routing event, and other mechanisms, interface designers and programmers have clear boundaries.

 
 

Dependency Property

In winform development, the common problem is that the value of a control changes, and other controls also change. The solution is not to writeCodeIf it is not through data binding, the interface and Code cannot be separated, and the latter is not flexible enough. In this regard, WPF can easily associate relevant attributes through XAML, and implement complex binding relationships through extension.

 
 

In general, I think WPF should be a continuation of the development of GUI. The complicated things in the original GUI can now be implemented through simple text.

References and tools:
Windows Presentation Foundation unleashed by Adam Nathan
Msdn
Essential Windows Presentation Foundation (*I strongly recommended and answered a lotWhyProblems)
Windows WPF source code
Reflector

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.