Windows 窗体的大多数限制和技巧对于大多数程序员来说都是常见的。 但自 .NET 3.0 以来,还提供了 WPF,即 Windows Presentation Foundation。 据说,您可以使用它使“性感的应用程序”变得更加容易,并且使用.NET 3.5 SP1,它的执行速度得到了很好的提升。
但另一方面,WPF 中很多事情的工作方式都不同。 我不会说这更困难,但你必须从头开始学习“一切”。
我的问题:当您必须创建一个新的 GUI 并且项目没有时间压力时,是否值得花费这些额外的时间?
Most restrictions and tricks with windows forms are common to most programmers. But since .NET 3.0 there is also WPF available, the Windows Presentation Foundation. It is said that you can make "sexy applications" more easy with it and with .NET 3.5 SP1 it got a good speed boost on execution.
But on the other side a lot of things are working different with WPF. I will not say it is more difficult but you have to learn "everything" from scratch.
My question: Is it worth to spend this extra time when you have to create a new GUI and there is no time pressure for the project?
发布评论
评论(30)
经过三个月的尝试在 WPF 上敲定业务线 (LOB) 应用程序,我考虑在我的项目中重新使用 Windows 窗体,并在研究其他人的意见时,遇到了这个线程...
是的,WPF 是一项出色的技术,它的好处远远超出了单纯的视觉效果。模板和绑定功能就是很好的例子。 整个对象模型提供了更多的灵活性和更广泛的可能性。 然而,这并不能使其成为未来 LOB 应用程序事实上的平台。
WPF 在将 GUI 与业务逻辑分离方面解决的“问题”并不是在 Windows 窗体中通过简单地从正确的体系结构和思维方式开始就可以轻松解决的问题。 甚至 WPF 的对象路径绑定功能也可以通过一些非常简单的帮助器类在 Windows 窗体中重现。 WPF 的数据模板功能非常好,但是在极少数情况下,当您完全不知道要在 Windows 窗体的任何给定部分上表示什么对象时,您也可以在 Windows 窗体中模拟它们。屏幕。
Windows 窗体的领先之处在于成熟度。 如果你不访问某个已经为你解决了 Windows 窗体问题的博客,你就不可能在 Google 上摇摆不定。 另一方面,WPF 的可用学习资源相对较少,可用的自定义控件也较少,并且尚未解决许多初期问题。
在做出 WPF 与 Windows Forms 决定时,必须考虑开发环境的成熟度。 Windows 窗体编辑器流畅、响应灵敏且直观。 有关错误的反馈会立即到达,解决方案通常很明显,并且 Windows 窗体中的编译 -> 调试 -> 编辑周期非常快。
另一方面,WPF 应用程序的设计时支持相对较差,设计视图在第一次遇到错误时就很容易畏缩,通常需要在修复后构建项目,然后设计人员才愿意开始工作再次。 考虑到在很多情况下它要么根本不起作用,要么产生完全不直观的结果,从工具箱中拖放组件也可能不受支持。 尽管 WpfToolkit 做出了承诺,但仍然没有一个可用的 WPF DataGrid 可以产生任何合理的性能或设计时友好性。
调试 WPF 应用程序有点像旧的 ASP.NET 调试范例...按 F5 -> 等等-> 发射-> 错误-> 停止-> 修复-> 点击F5 -> 等等-> 发射-> 错误-> 呻吟-> 停止-> 修复-> 按 F5.... 程序运行的所有 XAML 都被锁定,跟踪 XAML 特定问题通常很乏味。
简而言之,底线是 Windows 窗体开发工具将让您在 WPF 应用程序的一小部分时间内完成前端...尤其如果您创建大多数 LOB 都具备的主从网格或类似电子表格的界面。 使用 Windows 窗体,您可以从已经为您完成的 90% 的工作开始。
我是 WPF 架构的忠实粉丝。 我只是希望设计时工具集不像是预阿尔法调试构建。
编辑:此答案是关于 .NET 3.5 + Visual Studio 2008 发布的,但是带有 Visual Studio 2010 的 .NET 4.0 附带了 WPF 数据网格。 虽然新的WPF开发体验已经做了很多改进,但我在这里的答案保持不变,我想添加以下建议:
如果你急于做RAD 开发,使用 Windows 窗体。 如果您希望生成一个架构良好、可维护、可扩展、资源友好、多用户业务线应用程序,请考虑 ASP.NET MVC + HTML 5 + jQuery...我使用这些技术的项目取得了更好的效果为我的客户更快地取得成果。 MVC 提供与 WPF 相同的所有模板,并且 jQuery 支持动画和复杂的交互。 更重要的是,ASP.NET MVC + jQuery 解决方案不需要您的最终用户拥有具有良好图形硬件的现代桌面。
After three months of trying to hammer out a line-of-business (LOB) application on WPF, I reached a point of considering turning back to Windows Forms for my project, and in researching other people's opinions, came across this thread...
Yes, WPF is a brilliant technology and it has benefits that span far beyond mere eye-candy... the templating and binding capabilities are great examples. The whole object model offers more flexibility and broader possibilities. That doesn't, however, make it the defacto platform for future LOB applications.
The "problems" which WPF solves in terms of separating GUI from business logic aren't problems which can't be readily solved in Windows Forms by simply starting with the right architecture and mind-set. Even the object-path binding capabilities of WPF can be reproduced in Windows Forms with some very simple helper classes. The data template capabilities of WPF are very nice, but again they're nothing that you can't simulate in Windows Forms on those rare occasions when you absolutely don't know exactly what objects you're going to represent on any given part of the screen.
Where Windows Forms races ahead is in terms of maturity. You can't swing a dead cat on Google without hitting some blog where someone has solved a Windows Forms problem for you. WPF, on the other hand, has comparatively less learning resources available, fewer custom controls available, and hasn't had as many of its teething problems solved.
At the peak of making a WPF vs Windows Forms decision has got to be the maturity of the development environment. Windows Forms editors are slick, responsive and intuitive. Feedback about errors gets to you instantly, the solutions are usually obvious, and the compile->debug->edit cycle in Windows Forms is very quick.
WPF applications, on the other hand, have comparatively pathetic design time support, with the design view all-too ready to chicken out at the first encounter of an error, often requiring a project build after the fix before the designer is willing to kick in again. Drag'n'drop of components from the toolbox might as well not be supported, given the vast range of circumstances under which it either doesn't work at all, or yields completely unintuitive results. Despite the promise of the WpfToolkit, there still isn't a usable DataGrid for WPF that yields any kind of resonable performance or design time friendliness.
Debugging WPF applications is a bit like the old ASP.NET debugging paradigm... hit F5 -> wait -> launch -> error -> stop -> fix -> hit F5 -> wait -> launch -> error -> groan -> stop -> fix -> hit F5.... All XAML which your program is running is locked, and tracking down XAML specific problems is often tedious.
The bottom line, simply put, is that the development tools for Windows Forms are going to have you banging out front-ends in a fraction of the time of a WPF application... especially if you're creating master-detail grids or spreadsheet like interfaces, which most LOB have. With Windows Forms, you start with 90% of the work already done for you.
I'm a huge fan of the WPF architecture. I just wish the design-time tool-set didn't feel like a pre-alpha debug-build.
Edit: This answer was posted about .NET 3.5 + Visual Studio 2008, but .NET 4.0 with Visual Studio 2010 ships with a WPF data grid. While many improvements have been made to the new WPF development experience, my answer here remains unchanged, and I'd like to add the following suggestion:
If you're in a rush to do RAD development, go with Windows Forms. If you're looking to produce a well architected, maintainable, scalable, resource firendly, multi-user Line-Of-Business application, consider ASP.NET MVC + HTML 5 + jQuery... My projects with these technologies have resulted in better outcomes, sooner, for my customers. MVC offers all of the same templating that WPF does, and jQuery enables animations and complex interactions. More importantly, an ASP.NET MVC + jQuery solution doesn't require your end users to have modern desktops with decent graphics hardware.
我已经在客户的核心系统上使用 WPF 七个月了,我想与您分享一些关于学习和使用 WPF 作为业务线演示平台的经验的更多想法。
总的来说,我上面的评论仍然成立...... WPF 的设计时支持还没有到来。 如果您急于推出富客户端应用程序,请选择 Windows 窗体。 时期。 Microsoft 并不急于停止 GDI/Windows 窗体平台,因此您可以在未来一段时间内获得良好的支持。
WPF 并不容易掌握,但这不应该成为您决定是否投入时间和精力学习 WPF 的地方。 尽管 WPF 目前还不够成熟,但它是围绕一些有用的现代概念构建的。
例如,在 WPF 中,您对编写良好且具有健全验证逻辑的业务对象的投资是一项可靠的投资。 与 Windows 窗体不同,WPF 的数据绑定具有多种功能,允许界面控件对无效的用户输入做出反应,而无需编写 GUI 代码来检测这些错误。 这是很有价值的。
WPF 中的样式和模板功能也被证明是有价值的。 尽管人们普遍误解样式和模板的唯一用途是创建屏幕上的视觉效果,但事实是,这些功能显着简化了用户界面的编码,从而提供了丰富的反馈 - 例如根据情况禁用/启用自身的按钮底层业务逻辑层的状态,或者根据光标下对象的状态智能查找文本的工具提示等。
这些都为“没什么花哨”的业务应用程序提供了极其有价值的功能。 >,仅仅是因为它们可以轻松地保持界面与底层数据的一致。
简而言之:
接口,然后编写代码驱动
该用户界面,通常
还包括驱动您的代码
数据对象。
这是一个看似微妙的差异,但它对您重用代码的能力产生了巨大的影响......这就引出了一个问题:“Windows Forms 与 WPF 的问题实际上是一个投资决策吗?”
(这似乎已成为我最喜欢的话题。)
I'm seven months into using WPF on what has now become a core system for my customer, and I'd like to share some more thoughts with you about the experience of learning and using WPF as a line of business presentation platform.
In general, the comments I made above still hold... The design time support for WPF isn't here yet. If you're in a big rush to get a rich-client application out of the door, go with Windows Forms. Period. Microsoft aren't in any hurry to discontinue the GDI / Windows Forms platform, so you can count on good support for a fair time into the future.
WPF is not easy to master, but that shouldn't be where you leave your descision about whether or not to invest your time and energy into learning WPF. Despite its present lack of maturity, WPF is built around some useful, modern concepts.
In WPF, for example, your investment in well-written business objects with sound validating logic is a solid investment. Unlike Windows Forms, WPF's data binding is briming with features that allow interface controls to react to invalid user input without writing GUI code to detect those errors. This is valuable.
The styling and templating capabilities in WPF have proven to be valuable too. Despite the common misconception that the only use for styling and templating is to create on-screen eye-candy, the truth is that these features significantly simplify the coding of a user interface which gives rich feedback - like buttons that disable/enable themselves base on the state of the underlying business logic layer, or tooltips which intelligently find their text based on the state of the object under the cursor, etc.
These all add up to incredibly valuable features for "nothing fancy" business applications, simply because they make it easy to keep the interface congruent with the underlying data.
In a nutshell:
interface, then write code to drive
that user interface, which generally
also includes code to drive your
data objects.
It's a seemingly subtle difference, but it makes a huge difference in your ability to re-use code... which begs the question: "Is the Windows Forms vs WPF question actually an investment decision?"
(This seems to have become my favourite thread.)
是否有任何令人信服的理由使用 WPF
绝对! WPF 绝对令人难以置信! 这对于几乎任何项目来说都是一个重大好处,因为它具有 Windows 窗体所缺乏的许多特性和功能。
对于业务应用程序来说,最大的胜利将是:
对于实用程序和游戏,其他优势尤为突出:
最重要的是,您可以在 Windows 窗体中构建的任何大型 GUI 都可以在 WPF 中构建,只需三分之一(或更少)的工作量,并且看起来更好。
WPF 是否需要更多资源(特别是 RAM)
与 Windows 窗体相比,您确实付出了一定的代价,但代价很小。
关于 CPU 使用的另一点注意事项:由于其保留模式存储,动画和转换(运动、平移等)在 WPF 上实际上比在 Windows 窗体中更高效。 物体最初到达那里的速度较慢。
维护开销
在维护方面,WPF 比 Windows 窗体有巨大优势。 由于所有内容都是用以前 1/5 的代码完成的,因此需要维护的代码也减少了 1/5。 另外,所有样板文件都消失了,因此您可以专注于实际工作的代码。
XAML 的优点
XAML 是 WPF 的核心。 虽然 WPF 可以在没有 XAML 的情况下使用,但 XAML 使其非常易于使用。 XAML 具有 HTML 轻松指定用户界面的能力,但它的内置标记更强大,您可以轻松定义自己的标记。 (其实这样做很正常)。
XAML 的一些具体优点:
其他见解
我多年来一直梦想着像 WPF 这样的东西。 许多人已经实现了此功能的部分功能,但以这样的价格(0 美元)将所有功能都集中在一个地方是令人惊奇的。
WPF 是对 Windows 窗体的巨大范式转变,需要一些时间来适应,但花在学习它上的时间会带来数倍的回报。
即使五年后,WPF 仍然存在一些缺陷,但一旦您体验过它,它的强大功能将让您彻底震惊。 如果有人试图将您拖回 Windows 窗体,您只会又踢又叫。
尖端:
- 请获取用于开发的 Expression Blend 副本
- 偶尔手动编辑 XAML
- 当一开始看起来很奇怪时不要放弃
Are there any compelling reasons to use WPF
Absolutely! WPF is absolutely incredible! It will be a major benefit for practically any project because it has so many features and abilities that Windows Forms lacks.
For business applications the biggest wins will be:
For utilities and games, other advantages come to the forefront:
The bottom line is that any significant-size GUI you could build in Windows Forms can be built in WPF in a third of the effort (or less) and look way, way better.
Does WPF require more resources (RAM in particular)
You do pay a price compared to Windows Forms, but it is a small one.
One more note about CPU use: Animations and transforms (motion, translation, etc.) is actually more efficient on WPF than in Windows Forms because of its retained mode storage. It is the initial getting of the objects up there that is slower.
Maintenance overhead
WPF is a huge win over Windows Forms when it comes to maintenance. Since everything is done in 1/5 as much code as before, there is 1/5 as much to maintain. Plus all the boilerplate stuff is gone so you can focus on the code that actually does the work.
Benefits of XAML
XAML is the core of WPF. Although WPF can be used without XAML, XAML makes it incredibly easy to use. XAML has HTML's ability to easily specify a user interface, but its built-in tags are much more powerful, and you can easily define your own. (In fact, it is normal to do so).
Some specific advantages of XAML:
Other insights
I dreamed of something like WPF for many years. Many people have implemented portions of this functionality, but to get it all in one place and at such a price ($0) is amazing.
WPF is a huge paradigm shift from Windows Forms and will take some getting used to, but the time spend learning it will pay itself back many-fold.
WPF still has a few warts even five years later, but its power will totally blow you away once you experience it. If someone tries to drag you back to Windows Forms, you'll only go kicking and screaming.
Tips:
- Do get a copy of Expression Blend for development
- Do edit XAML by hand occasionally
- Don't give up when it seems strange at first
WPF 使您能够做一些令人惊奇的事情,我喜欢它......但每当开发人员问我是否认为他们应该转向新技术时,我总是觉得有义务验证我的建议。
您的开发人员是否愿意(最好是渴望)花时间来学习有效使用 WPF? 我从来没想过要谈论 MFC、Windows 窗体,甚至非托管 DirectX,但您可能不希望团队在正常开发过程中尝试“学习”WPF。 运输产品的周期!
您的至少一两个开发人员是否具有一定的设计敏感性,并且具有最终设计权限的个人是否对开发问题有充分的了解,以便您可以利用 WPF 功能来创建实际上更好的东西,而不仅仅是更“丰富多彩” ,以免费动画为特色?
您的目标客户群中是否有一定比例的运行在可能不支持您计划的功能的集成图形芯片组上,或者他们是否仍在运行 Windows 2000,这将完全消除他们的客户身份? 有些人还会问您的客户是否真的关心增强的视觉效果,但是,经历过 90 年代初期公司内部“我们的商业客户不关心颜色和图片”的辩论后,我知道您的竞争对手精心设计的解决方案会让他们关心,真正的问题是条件是否合适,使你能够提供一些让他们现在关心的东西。
该项目是否涉及从头开始的开发,至少对于表示层来说,以避免尝试连接到不兼容的遗留脚手架而带来的额外复杂性(与 Win Forms 的互操作不是无缝的)?
您的经理能否接受(或忽视注意到)开发人员生产力在四到六个月内大幅下降?
最后一个问题是由于我认为 WPF 的“FizzBin”本质造成的,有十种不同的方法来实现任何任务,并且没有明显的理由更喜欢一种方法而不是另一种方法,并且几乎没有可用的指导来帮助您制定任务。选择。 不仅您做出的任何选择的缺点只有在项目后期才会变得明显,而且几乎可以保证项目中的每个开发人员都采用不同的方法,从而导致严重的维护问题。 最令人沮丧的是,当您尝试学习该框架时,不一致的情况会不断地困扰您。
您可以在我的博客上的一个条目中找到更深入的 WPF 相关信息:
http://missedmemo.com/blog/2008/09/13/WPFTheFizzBinAPI.aspx
WPF enables you to do some amazing things, and I LOVE it... but I always feel obligated to qualify my recommendations, whenever developers ask me whether I think they should be moving to the new technology.
Are your developers willing (preferrably, EAGER) to spend the time it takes to learn to use WPF effectively? I never would have thought to say this about MFC, or Windows Forms, or even unmanaged DirectX, but you probably do NOT want a team trying to "pick up" WPF over the course of a normal dev. cycle for a shipping product!
Do at least one or two of your developers have some design sensibilities, and do individuals with final design authority have a decent understanding of development issues, so you can leverage WPF capabilities to create something which is actually BETTER, instead of just more "colorful", featuring gratuitous animation?
Does some percentage of your target customer base run on integrated graphics chip sets that might not support the features you were planning -- or are they still running Windows 2000, which would eliminate them as customers altogether? Some people would also ask whether your customers actually CARE about enhanced visuals but, having lived through internal company "Our business customers don't care about colors and pictures" debates in the early '90s, I know that well-designed solutions from your competitors will MAKE them care, and the real question is whether the conditions are right, to enable you to offer something that will make them care NOW.
Does the project involve grounds-up development, at least for the presentation layer, to avoid the additional complexity of trying to hook into incompatible legacy scaffolding (Interop with Win Forms is NOT seamless)?
Can your manager accept (or be distracted from noticing) a significant DROP in developer productivity for four to six months?
This last issue is due to what I like to think of as the "FizzBin" nature of WPF, with ten different ways to implement any task, and no apparent reason to prefer one approach to another, and little guidance available to help you make a choice. Not only will the shortcomings of whatever choice you make become clear only much later in the project, but you are virtually guaranteed to have every developer on your project adopting a different approach, resulting in a major maintenance headache. Most frustrating of all are the inconsistencies that constantly trip you up, as you try to learn the framework.
You can find more in-depth WPF-related information in an entry on my blog:
http://missedmemo.com/blog/2008/09/13/WPFTheFizzBinAPI.aspx
WPF 需要 Windows Vista 或 Windows XP SP2,这不是一个繁重的要求,但它是一个相关的要求。 如果您想在 Windows 2000 上运行(有些人仍然这样做),那么 WPF 将不适合您。
WPF 也是一项较新的技术,不如 Windows 窗体那么成熟,因此您可以选择 Windows 窗体作为风险较小的选项,特别是对于大型应用程序。
话虽如此,WPF 是未来。 Visual Studio 2010正在WPF中重写,这可能是迄今为止最大的WPF应用程序,也将是对该技术的真正考验。
显然,旧版 Windows 窗体应用程序将是另一种正确选择的情况。
WPF requires either Windows Vista or Windows XP SP2, which is not an onerous requirement, but it is a relevant one. If you want to run on Windows 2000 (which some people still do), then WPF won't work for you.
WPF is also a newer technology and not as proven as Windows Forms so you might choose Windows Forms as a less risky option, particularly for larger applications.
That being said, yes WPF is the future. Visual Studio 2010 is being rewritten in WPF, which will probably be the largest WPF application to date and it will also be a real test for the technology.
Obviously, legacy Windows Forms applications would be another situation where it is the correct choice.
正如其他人所说,无论哪种方式都有优点和缺点。 正如其他人所说,WPF 的优点包括:
但是,WPF 也有缺点,其中 Windows 窗体占据了上风:
最后,请记住,如果您愿意(或使用正确的第三方工具),您可以使用任一工具创建出色、有吸引力且引人入胜的 UI。 归根结底,两者都不一定在所有情况下都更好。 使用适合项目的东西。
As others have said, there are advantages and disadvantages either way you go here. The advantages of WPF, as others have said, include:
However, there are drawbacks to WPF, where Windows Forms comes out on top:
Finally, bear in mind that you can create great, attractive and engaging UIs in either tool, if you do the work (or use the right third-party tools). At the end of the day, neither is necessarily better in all circumstances. Use what feels right for the project.
WPF 的编程模型比 Windows 窗体更加开放和灵活,但与 ASP.NET MVC 一样,它在正确实现模型-视图-视图模型模式方面需要更多的纪律。
我的第一个使用 WPF 的 LOB 应用程序最终彻底失败,因为它是一个资源消耗大户,让我的最终用户的超低端笔记本电脑陷入瘫痪......这最终是因为我刚刚使用 WPF + LINQ to SQL 并期望得到一个好的结果...这就是 WPF 与 Windows 窗体的巨大差异...在 Windows 窗体中,您可以摆脱这种排序的东西。 WPF 比 Windows 窗体占用的资源要重得多,如果您不将应用程序设计得精益,那么您最终会变成一只 800 磅重的大猩猩。
不要回避 WPF...探索它。 但请注意,Windows 窗体编码中可接受的错误不会在 WPF 中产生良好的结果。 它们是根本不同的引擎,因此适用于根本不同的编码模式。
最后一句话:如果您确实继续使用 WPF,请充分熟悉与列表和网格一起使用的数据虚拟化。 简单的数据绑定 ListItem 或 GridCell 最终会成为 WPF 中庞大的逻辑 + 可视对象图,如果您不学习如何虚拟化,您的应用程序将无法在大型数据集上表现良好。
The programming model for WPF is more open and flexible than Windows Forms is, but like ASP.NET MVC, it requires a little more discipline in terms of correctly implementing Model-View-ViewModel patterns.
My first LOB application with WPF ended up as an utter failuire, because it was a resource hog which brought my end-user's very-low-end laptops grinding to a halt... and this was ultimately because I just lept in with WPF + LINQ to SQL and expected a good result... and this is where WPF diverges so strongly from Windows Forms... In Windows Forms, you can get away with that sort of thing. WPF is much heavier on resources than Windows Forms, and if you don't architect your application to be lean, you end up with a 800-pound gorilla.
Don't shy away from WPF... explore it. But be aware that the acceptable sins of Windows Forms coding won't produce good results in WPF. They're fundamentally different engines, which lend themselves to fundamentally different coding patterns.
Last Word: If you do go ahead with WPF, get well acquianted with data virtualization for use with lists and grids. What is a simple data-bound ListItem or GridCell ends up being a hefty logical + visual object-graph in WPF, and if you don't learn how to virtualize, you application won't perform well on large data sets.
WPF 的学习曲线非常陡峭,我建议您首先获得明显的书籍 (亚当·内森,
销售/Griffiths,以及
Chris Anderson)和
博客(乔什·史密斯等)。 只需为此做好准备,并确保您的项目允许您有时间学习 WPF。
除了学习技术之外,还需要花一些时间学习用于构建 WPF 应用程序的模式。 模型视图视图模型 (MVVM) 似乎已经获得了广泛的认可。
就我个人而言,我认为 WPF 是值得的,但要预先警告。 另请注意,您有效地将用户限制为 Windows XP SP2+ 和 Windows Vista。 我们已经做出了这个决定,但您可能有一些不同的要求。
There is a very steep learning curve to WPF, and I recommend you get the obvious books first (Adam Nathan,
Sells/Griffiths, and
Chris Anderson) and
blogs (Josh Smith, etc.). Just be prepared for it, and make sure your project allows you the time to learn WPF.
In addition to learning the technology, spend some time learning the patterns used to construct WPF applications. Model View ViewModel (MVVM) seems to be the one that has gained a great deal of acceptance.
Personally, I think WPF is worth it but be forewarned. Also note that you effectively restrict your users to Windows XP SP2+ and Windows Vista. We've made that decision, but you may have some different requirements.
这两种技术都有其优点和缺点。 在具有“经典”UI 的大型应用程序中,我会使用 Windows 窗体。 在需要丰富的用户界面(皮肤、动画、更改用户界面)的应用程序中,我会选择 WPF。 请查看文章WPF 与 Windows 窗体< /a> 比较 WPF 和 Windows 窗体。
Both of technologies have their pros and cons. In a large application with a "classic" UI I'd use Windows Forms. In an application which require a rich user interface (skinning, animations, changing user interface) I'd choose WPF. Please check the article WPF vs. Windows Forms comparing WPF and Windows Forms.
除了 UI 设计的灵活性之外,WPF 还有一些技术优势:
1.) WPF 不依赖 GDI 对象。嗯,我认为它使用 2 个 GDI 对象作为窗口实例本身,但这实际上没什么。 我在一定程度上参与过一个非常大的内部 Windows 窗体应用程序。 我们办公室的人有时会同时运行 3 或 4 个实例。 问题是它们经常遇到 Windows 2000、XP 和 Vista 固有的 10,000 个 GDI 对象限制。 当这种情况发生时,整个操作系统变得无响应,您将开始看到视觉伪影。 清除它的唯一方法是关闭应用程序。
2.) WPF 利用 GPU。WPF 将一些 UI 处理卸载到 GPU 的能力非常出色。 我只希望随着时间的推移,这方面会变得更好。 作为一名前 OpenGL 编程爱好者,我非常欣赏 GPU 的强大功能。 我的意思是,我的 100 美元显卡有 112 个内核,每个内核运行频率为 1.5 GHz(无论如何这都不是顶级的)。 这种并行处理能力可以让任何四核CPU相形见绌。
然而,WPF 仍然很新。 它无法在 Windows 2000 上运行。事实上,WPF 应用程序在重新启动后启动速度可能会很慢。 我在我的博客上谈论了所有这些:
http://blog.bucketsoft.com/ 2009/05/wpf-is-like-fat-super-hero.html
Aside from the flexibility in UI design, there are some technical advantages to WPF:
1.) WPF doesn't rely on GDI objects. Well, I think it uses 2 GDI objects for the instance of the window itself, but that's practically nothing. I've been involved to a certain extent in a very large internal Windows Forms application. The people in our office sometimes run 3 or 4 instances of it simultaneously. The problem is that they frequently run into the 10,000 GDI object limit inherent to Windows 2000, XP and Vista. When that happens the entire OS becomes unresponsive and you'll start to see visual artifacts. The only way to clear it up is to close applications down.
2.) WPF utilizes the GPU. The ability for WPF to off-load some of the UI processing to the GPU is brilliant. I only expect this aspect of it to get better with time. As a former OpenGL programming hobbyist I can appreciate the power that comes from the GPU. I mean, my $100 video card has 112 cores running at 1.5 GHz each (and that's not top of the line by any means). That kind of parallel processing power can put any quad-core CPU to shame.
However, WPF is still pretty new. It won't run on Windows 2000. And in fact, a WPF application can be slow to start up after a fresh reboot. I talk about all of this on my blog:
http://blog.bucketsoft.com/2009/05/wpf-is-like-fat-super-hero.html
我认为WPF值得学习。 恕我直言,一旦您掌握了速度,表单的设计工作就会容易得多。 我不会太担心“性感”的东西。 其中大部分只是一种时尚。 您可以在 WPF 中非常快速、轻松地制作“普通”Winforms 样式的应用程序。
在我看来,整个概念使设计变得更容易。
I think it is worth learning WPF. Once you are up to speed, design work on your forms is much easier IMHO. I wouldn't worry as much about the 'sexy' stuff. Most of this is just a fad. You can make 'normal' Winforms-style applications very quickly and easy in WPF.
The whole concept lends itself to easier design IMO.
我不同意这里的一些答案。 WPF 非常适合业务线 (LOB) 应用程序。 (青蛙设计的LOB客户端就是最好的例子)。 除了使您的 UI 引人注目(这在业务应用程序中不是必需的)的所有可能性之外,WPF 还为您提供了更多功能。
数据绑定和模板功能仅优于 Windows 窗体。 它还提供了一种更好的分离代码和表示的方法。
我们已成功将 WPF 用于 2-3 名开发人员的团队中的 2 个 LOB 应用程序。
您将面临的最大问题可能是 WPF 的陡峭学习曲线(与 Windows 窗体相比),这会降低不习惯 WPF 的开发人员的开发速度。
I don't agree with some of the answers here. WPF is really well suited for line of business (LOB) applications. (The frog design LOB client is the best example). And besides all the possibilities to have your UI be eye candy (which is not necessary in business applications), WPF offers a lot more for you.
The data binding and templating features are just superior to Windows Forms. It also offers a far better way for separating code and presentation.
We've successfully used WPF for 2 LOB applications in teams with no more than 2-3 developers.
The biggest problem you will face is probably the steep learning curve of WPF (compared to Windows Forms) which will decrease development speed with developers not used to WPF.
我们目前正在从 Windows 窗体在 WPF 中重写我们的应用程序。 是的,有一个陡峭的学习曲线,你必须“重新学习”一些东西,但这是非常值得的。 与 WCF 相结合,我们发现我们编写的代码比以前更少、更快、更健壮。
坚持一段时间,阅读 Adam Nathan 的书,并查看不断增长的第三方控件库,例如 Telerik 和 ComponentOne。 在我看来,一个缺点是设计工具 Expression Blend 非常难以使用使用。 最新版本仍处于测试阶段,但对于我们这些使用 Visual Studio 多年的人来说,感觉不太对劲。 是的,它主要面向设计师,但有些事情你在 Visual Studio 中无法做到。
We are currently rewriting our application in WPF from Windows Forms. Yes, there is a steep learning curve and you have to "re-learn" some things, but it is so worth it. And combined with WCF, we are finding we are writing less code, faster, and more robust than ever before.
Stick with it for a while, read Adam Nathan's book, and check out the ever growing library of third-party controls like those from Telerik and ComponentOne. One negative, in my view, is that the design tool, Expression Blend, is very awkward to use. The latest version is still in beta, but it just doesn't feel right to those of us who have used Visual Studio for years. Yes, it's mainly for designers, but some things you just can't do in Visual Studio.
如果界面设计对您很重要,请考虑 WPF,因为 WPF 可以提供更好的 UI 体验。 但 Windows 窗体经过了多年的发展,因此它已被证明是有效的,并且您可以找到许多精通该平台的程序员。
可移植性也可能是一个问题,WPF 仅适用于 Windows XP SP2 及更高版本。
此外,WPF 的学习曲线很陡,这意味着如果没有特定的 WPF 经验,交付高质量的产品并不容易。
Consider WPF if interface design is important to you, because WPF can deliver better UI experience. But Windows Forms has on its side the years of evolution, so it's proven to work and you can find many versed programmers for that platform.
Also portability may be an issue, WPF only works with Windows XP SP2 and up.
Also, WPF has a steep learning curve, meaning it's not easy to deliver a quality product without having specific WPF experience.
嗯,一个答案是“当您必须支持 1.1 或 2.0 时”,因为 WPF 是 .NET 3.0 的一部分。 WPF 存在已知的操作系统限制,并且存在一个明显的技能问题:如果您有一个了解 winforms 的开发团队,那么使用 winforms 生成健壮的代码可能会更容易。 但是,如果您正在编写大量 UI 代码,那么在某个时候可能值得开始学习 WPF。
WPF 还与 Silverlight 有很多共同点,因此它具有可转移的优势。
Well, one answer is "when you have to support 1.1 or 2.0", since WPF is part of .NET 3.0. There are known OS limitations for WPF, and there is an obvious skills issue: if you have a team of developers that know winforms, then it may be easier to turn out robust code with winforms. However, if you are writing a lot of UI code it is probably worth beginning to pick up WPF at some point.
WPF also shares a lot in common with Silverlight, so it has transferable benefits.
WPF 具有许多优点,例如出色的数据绑定功能、
关注点分离、设计和逻辑分离等...
作为一名开发人员,我喜欢使用 XAML 定义 UI 的能力,而不是使用 XAML
与 Windows 窗体设计器联系在一起,我很高兴知道我可以计算
另一位设计师让我的应用程序看起来不错。
就我个人而言,我不在乎旧版本的 Windows 是否不受支持,
但 WPF 的一大问题是(当前/曾经)不支持
由 Mono (http://www.mono-project.com) 提供,因此 WPF 应用程序不会在Mac 操作系统或 Linux。
(尽管 Silverlight 应用程序会)。
如果您有时间和资源投资学习 WPF,那就去做吧!
即使您要编写 Silverlight 应用程序来支持多个操作系统。
如果您需要桌面应用程序在多个操作系统上运行,请坚持使用 SWF。
WPF comes with many advantages such as superb data binding features,
separation of concerns, separation of design and logic etc...
As a developer I enjoy the ability to define my UI using XAML as opposed to
being tied to the Windows Forms designer and I feel good knowing I can count
on another designer to make my app look good.
Personally I don't care older versions of Windows are not supported,
but one of the big problems with WPF is that is is not (currently/ever) supported
by Mono (http://www.mono-project.com) so WPF apps will not run on Mac OS or Linux.
(Altough Silverlight applications will).
If you have the time and resources to invest in learning WPF, do it!
Even if you're going to be writing Silverlight applications to support multiple OS's.
If you need desktop applications to run on multiple OS's stick with SWF.
有很多差异。 我们喜欢 WPF 的原因是:
但是,我们坚持使用 Windows 窗体,因为
开发人员在学习 WPF 时
已经了解 Windows 窗体。
降低。
There are many differences. We loved WPF for:
However, we stuck with Windows Forms because:
developer to learn WPF when they
already know Windows Forms.
lower.
在决定使用哪一个时,最重要的考虑因素是考虑目标受众安装的 .NET Framework。 我发现更多的人拥有较低的 .NET Framework 版本,仅支持 Windows 窗体,但这只是我个人的经验。
The biggest consideration when deciding which one to use is to consider what .NET Framework your target audience have installed. I find that more people have the lower .NET Framework versions that only support Windows Forms, but that's just my personal experience.
WPF 的优点是可以更轻松地使用自定义控件和动画创建美观的 GUI。 WPF 还有助于进一步分离表示层和逻辑层。 如果您有设计师,它可以让您将 95% 的工作交给非编码人员,并允许编码人员处理逻辑。 缺点是 Expressions Blend 的软件成本较高,并且缺乏任何运行良好的 Visual Studio 代码分析工具,因为它们往往会陷入尝试呈现 XAML 的框架调用中。 我确信还有其他人,但这是我们真正看到的唯一两个。
主要考虑因素是您是否希望要求客户必须安装 .NET 3.0 甚至更好的 .NET 3.5 SP1。 你会得到一些负面反馈
The advantages of WPF is that it is much easier to create nice looking GUI's with custom controls and animations. WPF also helps further serparate the presentation and logic layers. If you have designers, it allows you to farm of 95% of this work to non-coders and allows the coders to work on logic. The disadvantages are the software costs for Expressions Blend, and the lack of any of the Visual Studio code profiling tools working well as they tend to get caught up in the frameworks calls in trying to render XAML. I am sure there are others but these were the only two we really saw.
The main consideration is if you wish to require your customers to have to install .NET 3.0 or even better .NET 3.5 SP1. You will get some niegative feedback
WPF 使将表单设计工作移交给实际的设计师(而不是披着设计师外衣的开发人员)变得更加容易。 如果这是您想要做的事情,WPF 就是您的答案。 如果经典 Windows 风格的按钮没问题,那么 Windows 窗体可能是最佳选择。
(多个答案都声称,如果界面设计“对您来说很重要”,您应该使用 WPF,但这非常模糊。界面设计始终是“重要的”。)
WPF makes it much easier to hand off the forms design work to an actual designer, not a developer in designer's clothing. If that's something you'd like to do, WPF is your answer. If the classic Windows styled buttons are fine, then Windows Forms is probably the way to go.
(Multiple answers make the claim that you should use WPF if interface design is "important to you" but that's pretty vague. Interface design is always "important".)
如果您有 MSDN 许可证,请查看表达式工具。 它是专门为 WPF 设计的,直接导出到 Visual Studio,它可以帮助您轻松过渡。
If you have an MSDN license, check out Expression tools. It's designed explicitly for WPF, exports directly to Visual Studio and it may help ease your transition.
如果您只关心支持 Windows 并且不介意学习它所需的时间,请选择 WPF。 它快速、灵活、易于重新设计,并且拥有出色的工具来使用它。
If you only care about supporting Windows and don't mind the time it takes to learn it, go with WPF. It's fast, flexible, easy to reskin, and has great tools to work with it.
另外一个好处是,Silverlight 基于 WPF,从其中一个开始,您就可以了解如何与另一个一起工作。 如果事情继续基于网络,那么拥有可以轻松传输到浏览器(或 Windows Live Mesh)的先验知识(和现有代码库)可能有助于为您的软件带来额外的生命力。
As a side bonus, Silverlight is based on WPF and starting with either lets you gain the know how for working with the other. If things continue to go web based, having prior knowledge (and a library of existing code) to transfer easily to the browser (or Windows Live Mesh) might help give your software an extra lease of life.
如果您决定使用 WPF,考虑到上面答案中已经解释的优缺点,我强烈建议您阅读此 比利·霍利斯的 dnrTV 剧集
If you decide to go with WPF, considering pros and cons already explained in the above answers, I highly recommend going through this dnrTV episode with Billy Hollis
在 DotNetRocks 第 315 集 中,Brian Noyes 对此进行了广泛讨论。
In DotNetRocks episode 315, Brian Noyes discusses this extensively.
WPF 中的文本呈现存在一个已知问题。 许多用户报告称,大量使用抗锯齿和像素混合会导致文本模糊。 在某些情况下,这是一个重大问题,据我所知,微软在某种程度上已经承认了这一点。
There is a known issue with text rendering in WPF. Many users report that the heavy use of anti-aliasing and pixel-blending used causes blurry text. This is a big deal breaker in some circumstances and, as far as I know, has been acknowledged by Microsoft at some level.
在过去的 3 1/2 年里,我一直在进行 Windows 窗体开发(在两家公司)。 这两个应用程序都被广泛使用,最终都出现了 GDI 问题。 大型 Windows 窗体应用程序最终将耗尽 GDI 资源 - 导致最终用户必须重新启动。
For the last 3 1/2 years I've been doing Windows Forms development (at two companies). Both applications were used extensively and ended up having GDI problems. Large Windows Forms applications will eventually run out of GDI resources - causing the end user to have to reboot.
Scott 正在抱怨 Expression Blend 以及如何解决作为一名开发人员,这对他来说没有意义。 我对 Expression Blend 的第一反应就是这样。 然而,现在我认为它是一个非常宝贵的工具,但这实际上取决于您是什么类型的开发人员。
我是用户界面开发人员,必须执行 Integrator 角色,我最终发现 Expression Blend 对于创建样式和以所见即所得的方式控制模板非常有用。 我几乎总是让 Expression Blend 和 Visual Studio 同时在同一个项目上运行。
我还认为在 Expression Blend 中进行操作并查看被吐出的 XAML是学习 WPF API 的绝佳方法...就像在 Windows 窗体中使用设计器一样,检查它生成的 C# 代码有助于学习如何使用您在那里设计的任何内容。
表达混合很有帮助。 请尝试一下,尤其是当您正在处理应用程序的视觉效果时。
Scott is complaining about Expression Blend and how it doesn't make sense to him as a developer. My first reaction to Expression Blend was like that. However, now I see it as an invaluable tool, but it really depends on what type of developer you are.
I am user interface developer that has had to perform the Integrator role, and I eventually found Expression Blend invaluable to create styles, and control templates in a WYSIWYG manner. I almost always have Expression Blend and Visual Studio up an running on the same project at the same time.
I also think that playing around in Expression Blend and taking a look at the XAML that gets spit out is an excellent way to learn the WPF API ... much like using the designer in Windows Forms and checking the C# code it spits out is helpful in learning how to use whatever you are designing there.
Expression Blend is helpful. Just give it a try, especially if you are working on the visuals for the application.
引用自马克之前的帖子:
我认为这更多的是一种设计选择,而不是您是否使用 Windows 窗体或 WPF。 然而,我可以理解某些技术可能更适合特定的方法。
A quote from an earlier post from Mark:
I would argue that this is more of a design choice, rather than whether or not you are using Windows Forms or WPF. However, I can appreciate that certain technologies might be better suited for a particular approach.
仅当您没有 WPF 专业知识并且您不想投资它时:)
Only if you don't have WPF expertise and you don't want to invest in it :)