.net 为什么我应该在 Winforms 上使用 WPF?WPF 优于 Winforms 的任何例子?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1926000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 13:41:45  来源:igfitidea点击:

Why should I use WPF over Winforms? Any examples of WPF outperforming Winforms?

.netwpfwinforms

提问by Cory Charlton

There is a similar question at WPF versus Windows Formswhich has some good information but in my personal experience I see no reason to use WPF over Winforms. With WPF initially there was lots of talk about it's multi-threaded functionality but in use I see no benefits.

WPF vs Windows Forms有一个类似的问题,其中有一些很好的信息,但根据我的个人经验,我认为没有理由在 Winforms 上使用 WPF。WPF 最初有很多关于它的多线程功能的讨论,但在使用中我看不到任何好处。

I have two applications that do the same thing, one in WPF and on in Winforms. The Winforms application blows the WPF application away in terms of performance (by a factor of 10) and looks just as nice.

我有两个应用程序做同样的事情,一个在 WPF 中,一个在 Winforms 中。Winforms 应用程序在性能方面比 WPF 应用程序更胜一筹(10 倍)并且看起来也一样好。

Granted I am more proficient in Winforms applications than WPF.

当然,我比 WPF 更精通 Winforms 应用程序。

回答by TimothyP

There is another discussion on the subject here: When is Windows Forms the correct choice vs WPF?

这里还有关于这个主题的另一个讨论: Windows Forms 与 WPF 相比,什么时候才是正确的选择?

The Winforms application blows the WPF application away in terms of performance (by a factor of 10) and looks just as nice.

Winforms 应用程序在性能方面比 WPF 应用程序更胜一筹(10 倍)并且看起来也一样好。

WPF is about more than just fancy graphics... I'm not a designer, hell I have no feeling for colors (to a point where my fiancee decided I can no longer buy my own clothes) but I love WPF. DataBinding support for example is amazing not to mention how easy it is to create a ItemTemplate for a ListBox (remember overriding the draw methods in Windows Forms just to get 2 lines of text and an image in a ListBox item?)

WPF 不仅仅是花哨的图形......我不是设计师,地狱我对颜色没有感觉(我的未婚妻决定我不能再买自己的衣服了)但我喜欢 WPF。例如,DataBinding 支持令人惊奇,更不用说为 ListBox 创建 ItemTemplate 是多么容易(还记得覆盖 Windows 窗体中的 draw 方法只是为了在 ListBox 项中获取 2 行文本和图像吗?)

As for performance... in my experience the improvement can only be noticed if you're using Windows Vista / 7 with a GPU. (And of course the way you write code).

至于性能……根据我的经验,只有在使用带有 GPU 的 Windows Vista / 7 时才能注意到这种改进。(当然还有你编写代码的方式)。

Perhaps it was a mistake by Microsoft to market that WPF is all about pink elephant graphics while it does so much more. (They made a similar mistake with the rushed release of Silverlight 1, which in my opinion they should have skipped all together).

或许微软将 WPF 宣传为粉红色大象图形是一个错误,而它却做得更多。(他们在匆忙发布 Silverlight 1 时犯了类似的错误,在我看来他们应该一起跳过)。

回答by Phillip Ngan

WPF

WPF

  1. allows a designer/non-programmer to improve the appearance of the UI, separate from the code. Designers can use tools like Expression Blend to heavily modify the look of an app.
  2. the knowledge required for writing WPF is almost entirely transportable for writing Silverlight code, so you are climbing one learning curve for two technologies
  3. is heavily and actively promoted by Microsoft, and has probably more future than WinForms. WinForms will go the way of MFC before WPF does.
  1. 允许设计师/非程序员改进 UI 的外观,与代码分开。设计人员可以使用 Expression Blend 之类的工具来大量修改应用程序的外观。
  2. 编写 WPF 所需的知识几乎完全可以用于编写 Silverlight 代码,因此您正在攀登两种技术的一条学习曲线
  3. 由微软大力推广,可能比 WinForms 更有前途。WinForms 将在 WPF 之前采用 MFC 的方式。

on the other hand:

另一方面:

  1. the learning curve is heavier for WPF than Winforms
  2. designer support is lacking compared to Winforms, although this may change with Visual Studio 2010
  3. the current trend is to use View-ViewModel-Model to build applications: this is further learning on top of the WPF framework, but is worth the effort if you are going to build anything beyond simple UI's
  1. WPF 的学习曲线比 Winforms 重
  2. 与 Winforms 相比缺乏设计器支持,尽管这可能会随 Visual Studio 2010 改变
  3. 当前的趋势是使用 View-ViewModel-Model 来构建应用程序:这是在 WPF 框架之上的进一步学习,但如果您要构建简单 UI 之外的任何东西,则值得付出努力

If performance (speed and resource requirements) is your criteria for a good UI platform for Windows, then the winner is a native Win32 application. You adopt another technology for what they have to offer, and ultimately WPF has more to offer than WinForms.

如果性能(速度和资源要求)是您选择适用于 Windows 的良好 UI 平台的标准,那么获胜者是本机 Win32 应用程序。你采用另一种技术来提供他们所提供的东西,最终 WPF 比 WinForms 提供更多。

回答by kyoryu

The biggest reason to go with WPF isn't eye-candy. The real gains are in terms of reliability, productivity, and allowing the artistic types to modify the appearance of your UI without involving engineers.

使用 WPF 的最大原因不是吸引眼球。真正的收益在于可靠性、生产力以及允许艺术类型在不涉及工程师的情况下修改 UI 的外观。

回答by Ronald

Biggest issue with WPF is that the toolset is lame and learning curve is huge. So far uptake on WPF has been very low mostly because of the issues I just mentioned. According to Microsoft WPF is the future and they have invested heavily in it. Infact next version of Visual Studio is written in WPF (http://www.onedotnetway.com/writing-visual-studio-2010-shell-in-wpf-reflects-confidence/)

WPF 的最大问题是工具集蹩脚,学习曲线巨大。到目前为止,WPF 的采用率非常低,主要是因为我刚刚提到的问题。根据微软的说法,WPF 是未来,他们在这方面投入了大量资金。事实上,Visual Studio 的下一版本是用 WPF 编写的(http://www.onedotnetway.com/writing-visual-studio-2010-shell-in-wpf-reflects-confidence/

However it still remains to be seen if WPF will ever become mainstream. The framework is awesome and it can do really cool stuff mostly related to eye-candy. Microsoft calls it UX but in plain English it is eye-candy. Most of the applications don't need it.

然而,WPF 是否会成为主流仍有待观察。该框架非常棒,它可以做非常酷的事情,主要与吸引眼球有关。微软称它为 UX,但用简单的英语来说它很吸引人。大多数应用程序不需要它。

回答by scptre

WinForms and WPF are both great frameworks the question is what is best suited to your application. If you need a fluid gui with animated controls and very themable styles, or are just creating a very graphical user interface WPF is very good for that kind of application. WinForms can be very limiting at times because the controls are what they are you can create user controls to add things to them but changing their appearance can be difficult if you have a very specific look in mind.

WinForms 和 WPF 都是很棒的框架,问题是什么最适合您的应用程序。如果您需要具有动画控件和非常主题化的样式的流畅 gui,或者只是创建一个非常图形化的用户界面,WPF 非常适合此类应用程序。WinForms 有时可能非常有限,因为控件就是它们的本质,您可以创建用户控件来向它们添加内容,但是如果您有一个非常具体的外观,则更改它们的外观可能会很困难。

A good comparison would be looking at the difference between a WinForms application and a silverlight application. Silverlight and WPF share a common framework and it will help you to understand the differences between the two.

一个很好的比较是查看 WinForms 应用程序和 Silverlight 应用程序之间的区别。Silverlight 和 WPF 共享一个通用框架,它将帮助您了解两者之间的差异。

Have a look at this silverlight and wpf library and you will see some of the things that can be done in a wpf environment.

看看这个 silverlight 和 wpf 库,你会看到一些可以在 wpf 环境中完成的事情。

Silverlight Library: http://demos.telerik.com/silverlight/

银光图书馆: http://demos.telerik.com/silverlight/

WPF Library: http://demos.telerik.com/wpf/

WPF 库: http://demos.telerik.com/wpf/