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