Four years of WPF, especially not enough to replace winform

Source: Internet
Author: User
Tags visual studio 2010

Four years of WPF, especially not enough to replace winform

WPF has been in the mountains for four years. As the official owner of the next-generation UI system. However, whether the new manager is competent is still a concern of many developers. By using WPF to rewrite the editor of Visual Studio 2010, Microsoft finally confirmed the competency issue. Of course, it also made many important improvements to WPF, in particular, it finally solves the problem of text visibility. Therefore, at least from. Net 4, WPF should be safe for important development projects.

However, using WPF is not as smooth as using winform.

First, it is too complicated and the entry threshold is very high. This complexity is partly due to its ambition to unify desktop and web development. Using a set of frameworks to support both desktop and web is good, but it also inherits the complexity of both. If you have both winform and ASP. NET development experience, you will feel that this merger is natural and promising. Of course, WPF has a higher goal, that is, to challenge flash. This kind of one-to-three spirit is commendable. It can be imagined how powerful it will be to defeat the different martial arts leaders of the three schools at the same time. But how many developers we learn and use WPF to target two or even three fields at the same time? Even if we only need to face one of the fields, we have to face all the complexity of WPF. Of course, there are also potential benefits. You can easily introduce technologies in two other fields.

Secondly, for winform developers, it may be more difficult to get started with WPF, because the most basic thing-making interface XAML is completely web style and ideas. Most of the original winform knowledge and skills are no longer applicable. The first choice is document, window, page, navigationwindow, and so on, rather than a simple form. After creating a window, if you expect to design a form like winform, you will find that its window designer is basically a joke. Do you still need to write the XAML honestly, I am glad that I have learned some HTML. If you can't stand the hand-written XAML, you can download expression blend, which is similar to the Flash editor. At this time, you will be glad that you have made some artists and will use flash.

After that, you will find that adding a tool button cannot directly specify the icon and text at the same time. You must also nest a stackpanel. When disable, the icon will not become grayed out and you need to write your own style to implement it; the overflow popup button at the end of the toolbar is always annoying. To hide it, you have to be the best on the controltemplate. No dropdownbutton is available. You need to implement it yourself ...... Many of the things used in winform suddenly disappeared. Although it can be achieved through the powerful style system and composition, after all, it takes a lot of effort.

Resource addition and management are simpler than before. You only need to add the file to the project, organize the directory structure freely, and set the build action of the file to resource. But the paths that reference resource files are evil. I don't know which kind of spirit is different from that of ordinary people who invented this pack URI rule (such as pack: // application :,,, /referencedassembly; v1.0.0.1; component/myresourcepath/resourcefile. XAML), as soon as I saw it, I wanted to pack sandbags. Fortunately, in most cases, you only need the relative path to omit the previous string of objects that are not flat.

Data Binding is one of the biggest changes in programming mode. Almost all data interaction with the UI is implemented through binding. In simple cases, data binding is very simple and powerful, it is much stronger than Data Binding in winform. However, the complexity of the situation is confusing. To be more complex, you must write a viewmodel layer, that is, to write an interactive class between the UI and the business logic. The UI is bound to the attributes of this class. Next, we should consider the formatting of data display, such as how to display a floating point number into a hundred-point output, combining multiple attributes into one output, and verifying the validity of user input; limit the number of characters that can be entered. You want to accept the input when you press the Enter key ...... These are not directly problems with ready-made support. You need to write some code to solve them.

In addition, the WPF language localization tool supports almost zero equivalent, only complex and difficult-to-use command line tools, or SDK sample compilation. Only third-party tools are required for Local translation.

More interestingly, the WPF program uses the en-US culture by default. No matter what the current system is, you need to write your own code to set the language attribute of the window or control when the program starts, or override its frameelement. the default value in metadata of languageproperty. Of course, this is not a bug, but by design. The cause is a design error of the earliest. net.

 

The original design. net, they plan to support globalization and localization from the basic library to adapt to the increasingly globalized market in the future, so all string formatting functions use the current system by default. However, in all other development languages, the default value is the en-US standard. As a result, a large number of programs do not consider this difference. The first result is the performance loss. Considering that the local string processing overhead is much slower than the simple binary string processing, second, a large number of bugs may occur in different language systems. For example, a floating-point number "1.23" text is generated in the German system, which is "" and sent to the English System for reading. An error occurs in parsing. For example, the case sensitivity of different languages is different, and the case sensitivity may be different in different language systems. Unexpected bugs may occur in file name and path processing. Development. NET 2.0 ,. NET developers have realized this error, but they cannot change the existing API. Therefore, they can only add overload with new parameters for these functions, we recommend that you do not use old APIs, but use long functions such as string. equals (string another, stringcomparison comparisontype), using string. format () is also best to use the specified culture overload, make full use of cultureinfo. invariantculture. WPF designers have fully learned this lesson, so the default is always en-us, and the location to be localized must be displayed and specified.

Besides, ilmerge cannot merge WPF Assembly correctly because it cannot modify the reference string of resources in baml. This means that the ilmerge-based obfuscator also has this problem. However, for obfuscator, it is not easy to support WPF. Because WPF depends on data binding, a large number of object attribute name strings are used in data binding. After compilation, The XAML will be compiled into binary baml, And the baml format is not public. In this way, the attribute name of the referenced object cannot be modified.

All in all, there are still many ways to go for WPF. The future is bright and the road is tortuous. The future is WPF and winform, but are Korean in the final sense?

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.