WPF learning experience

Source: Internet
Author: User

Recently, I started to learn about WPF, read some materials, and write down my learning experience. I hope it will help you.

Developed after WinForm, WPF is more advanced than WinForm in terms of technology development. I think WPF has the following advantages over WinForm:

Solve the Window Handle Problem
Complex GUI applications in Windows GDI or WinForm development use a large number of controls, such as Grid. Each control or Grid cell is a small window and will use

A Window handle, although the control vendor provides a lot of optimization methods, but still encounter Out of Memory or "Error Create Window handle", leading to program return

Output.

WPF completely changes the display mode of the control. If the control does not use the Window, it does not occupy the Window handle. Theoretically, if a WPF has only one main window

Use a Window handle (if hidden windows used for Dispatcher are ignored ). Therefore, Windows handle is not enough for the wpf gui program.

Multi-thread processing
During WinForm program development, the biggest headache is that the worker thread modifies the properties of the control and causes the program to crash, and this illegal operation does not fail every time.

The WinForm control provides the InvokeRequired attribute to determine whether the current thread is the control creation thread. The problem is that when the control tree is deep, this attribute will be slow.

At the beginning of the WPF design, multithreading was taken into account. Most WPF classes inherit from DispatcherObject. DispatcherObject is actually

A simple encapsulation. Dispatcher provides methods similar to InvokeRequired (CheckAccess ). This method only compares the thread ID, so it will be very fast. In addition,

Dispatcher provides priority queue, asynchronous call, and Timer functions, simplifying the development of multi-threaded GUI programs.

Control Composition
To implement a Checkbox drop-down menu in WinForm, complicated Window messages will have to be processed. However, using the Content Model and Layout System of the WPF control, WPF

Controls can include any type of controls or even. Net CLR objects. Many modern control manufacturers also provide Composition controls. The implementation method is similar to the Content Model of WPF.

Similar. The WPF development team should learn from many Infragistics ideas. With this foundation, it is easier to develop new WPF controls.

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,

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 write code or bind data.

The former is unable to separate the interface and code, and the latter is not flexible enough. In this regard, WPF can easily associate relevant attributes through XAML, and implement the complex operation through Extension.

Complex binding relationships.

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 (* strongly recommended, answered many WHY questions)
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.