tags:

views:

11161

answers:

8
+35  Q: 

WPF versus Winforms

  1. What are the advantages and disadvantages between using WPF (Windows Presentation Foundation) over Winforms?
  2. What are the considerations that need to be made when choosing between the two?

Thanks.

+5  A: 

The biggest consideration when deciding which one to use is what Framework will your target audience have installed? I find that more people have the lower Framework versions that only support Winforms, but that's just my personal experience.

Jon Tackabury
In November 2009 between 20-50% of all computers altready have NET Framework 3.0 or above installed so they can already run WPF. For those who don't, you can include it on your CD or you have your application download the NET Framework Client Profile when it is installed. The Client Profile takes 2 minutes to download on a 256K DSL line, and you can save bandwidth by setting it to download from Microsoft's web site.
Ray Burns
+1  A: 

WPF's support for declarative UI through XAML, rich controls templating and styling and tools like Blend, makes it lot better for designers to work with developers on the same project. Plus, it gives the developers the flexibility of attached dependency properties and the extremely powerful databinding. In addition Silverlight supports a subset of XAML and the same control classes as WPF, so your application can be ported as RIA with minimal efforts.

I would choose WPF over WinForm any day. Even if the target machines have only .Net 2.0, if the user can install additional programs, the new .NEt Framework Client profile makes it quite easy to deploy WPF applications.

The only reason I might decide to stick with WinForms is if the product will be deployed on machines that are locked down and have only .Net 2.0 or .Net 1.1.

Franci Penov
+5  A: 

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

Alex
You can include the NET Framework on your CD, or you can set it up to do a 2 minute download from Microsoft's web site (assuming 256K DSL line). In either case, it can be installed as part of your application's installation. This also works with ClickOnce.
Ray Burns
I have 2M DSL and the whole setup takes generally half an hour when it doesn't crashes on My (usually clean install) XP machines.
Camilo Martin
Ray Burns
Maybe I was not clear enough. Download Speed and not clicking buttons have only partial imact on deciding if you wish to require installing the framework. The biggest consideration is if any of your customers would be enterprise or education situations where the local user may NOT have the option to install it.
Alex
+7  A: 

There are many differences. We loved WPF for:

  1. The declarative style of programming.
  2. Animations and state transitions
  3. Blend is a great tool
  4. Good style support.

However, we stuck with Forms because:

  1. The extra time it takes for a developer to learn WPF when they already know Forms.
  2. WPF will not run on windows 2000 or lower.
amcoder
Is Windows 2000 so important?? I mean, how many people are stuck in that archeological OS?
Camilo Martin
It is because Microsoft is sponsoring some special school version (Windows 2k) for old notebooks and PCs - I think the name of the project is FreshStart...
cevik
Yeah, at least WinXP... Win2000?! c'mon!
Andrei Rinea
+26  A: 

As others have said, there are advantages and disadvantages either way you go here. The advantages of WPF, as others have said, include:

  • The ability to make very rich UIs relatively easily.
  • Easier animation and special effects
  • Inherent scalability (use the Vista magnifier tool on a WPF app, and on a WinForms app: Note that in the WPF app, all the vector art scales beautifully)
  • (OPINION ALERT) I feel it's "easier" to do document-oriented systems in WPF

However, there are drawbacks to WPF, where WinForms comes out on top:

  • WPF's in-box control suite is far more limited than that of WinForms.
  • There's greater support in the 3rd-party control space for WinForms. (That's changing, of course, but think about it: WinForms has been around since 2001; WPF just a few years. By advantage of time, WinForms has greater support in the community.)
  • Most developers already know WinForms; WPF provides a new learning curve

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 3rd party tools). At the end of the day, neither is necessarily better in all circumstances. Use what feels right for the project.

John Rudy
Your statement that "WPF's in-box control suite is far more limited than WinForms" could be misunderstood. WPF's in-box control suite can do *far* more than WinForms because every control can be templated and is mulit-purpose. Almost everything in WinForms maps directly to simple WPF. HOWEVER in the original WPF release (NET Framework 3.0) there WERE three functions missing that WinForms had built in: DateTimePicker, NumericUpDown, DataGrid. All three are easy downloads, plus the latest WPF (3.5 SP1) has added a DataGrid to the package.
Ray Burns
In addition there are a few features of individual WinForms controls not present, such as AutoComplete for TextBoxes. By this time (November 2009), easy solutions have been posted on blogs for all of these. So there is no longer any reason to select WinForms because WPF is missing any controls. And if WPF is missing a vendor-supplied control you need, you can still use WinForms integration for that control.
Ray Burns
For me, the biggest advantages of WPF are its data binding, templating, and layout.
Ray Burns
"think about it: WinForms has been around since 2001" : yes, but WinForms didn't evolve since .NET 2.0...
Thomas Levesque
Understand when the answer was written ... Over a year ago, this was all true. Now, yes, I'd probably go with WPF in a heartbeat. :)
John Rudy
+1  A: 

Hi! What about performance of WPF? What are the REAL hardware requirements?

Cheers from Argentina!

pabloide86
I test my apps on a 200MHz machine with 384MB RAM and a graphics card from 1998. They are usually comparable in performance to equivalent WinForms apps.
Ray Burns
+22  A: 

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 WinForms lacks.

For business applications the biggest wins will be:

  • The fantastic data binding and templating make the biggest difference. Once a decent data model is in place, it only takes a few clicks to create a data template and use Blend to configure exactly how your object will look using drag-and-drop. And binding to things like color or shape is trivial.
  • Screen layout is incredibly flexible. Not only can everything in WPF smoothly adjust to container size and shape changes, but items can trivially be enlarged and rotated, and even extend outside their containing frame.
  • Ordinary objects can be presented any way you like, can easily have different presentations in different screens, can share presentation, and can adapt their presentation to changes in data values.
  • If you need to print, rendering to the printer is trivial. Properly configured, WPF makes Crystal Reports or SQL Server Reporting Services look like a child's toy.
  • Your user interface will look and feel much more dynamic, including nice features such as buttons that animate when you pass the mouse over them.

For utilities and games, other advantages come to the forefront:

  • You can easily add shapes, lines, and arbitrary drawings to your application without using an external editor. Every component of these can be data-bound and animated, or controlled by code. In WinForms you ususally just have to import a bitmap and use it as-is unless you want to go to a lot of work.,
  • Animations are cool! Users will be really impressed, as long as you don't overdo it. They can also help people see what is going on and reduce the need for hilighting. For example, when dragging an object you can animate the target to show what will happen if you drop it.
  • Colors, gradient fills, brushes, fancy fonts, rotation of any objects, tile brushes, etc. Anything you want graphically is yours for the asking.
  • Incredibly customizable. I needed to draw railroad tracks for one applicaiton so I could drop a train on them. A couple of hours later I had railroad tracks I could draw anywhere on the screen using bezier curves, and they would join and switch automatically.

The bottom line is that any significant-size GUI you could build in WinForms 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 WinForms, but it is a small one.

  • RAM can go up or down depending on your implementation. WPF stores its data more efficiently so individual objects are smaller, but there tend to be more objects in WPF than in WinForms so this balances out, and either one can come out ahead.
  • CPU will go up compared to WinForms. In my experience, the actual update of WPF objects onscreen takes about 2x as much CPU as normal WinForms rendering. If your application spends most of its time updating the screen, WPF may not be for you. But in that case you're probably not using WinForms either: Most serious games are written directly to DirectX.
  • Disk usage will be slightly less for WPF because it takes so much less code than WinForms. The data will be the same size, of course.

One more note about CPU use: Animations and transforms (motion, translation, etc) is actually more efficient on WPF than in WinForms 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 WinForms 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:

  • Your entire UI is defined in a text file that is easy to read and maniuplate, both for users and tools
  • MarkupExtensions allow Bindings to be specified in a clear and simple way
  • Type converters allow properties with complex types to be easily specified, eg. you can say Brush="Green" or you can specify a radial gradient brush with three stops.
  • You can create your own elements
  • You can easily leverage WPF's powerful "attached properties"

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 WinForms 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 5 years later, but its power will totally blow you away once you experience it. If someone tries to drag you back to WinForms, 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

Ray Burns
+1 For the data binding
Danny Varod
+1 It's pity I cannot add more than +1 :-)
MartyIX
+1 `I dreamed of something like WPF for many years. Many people have...`
Veer
+1 for sheer enthusiasm :)
Colin Pickard
»including nice features such as buttons that animate when you pass the mouse over them« you mean like Windows does for any normal button already, too?
Joey
@Johannes: No I don't. All Windows does is put a hilight on the button (and even this works only if it is a plain-vanilla button). WPF can do far, far more. For example, a button may have a door icon that hinges open when you hover over it, or an insertion pointer can appear elsewhere in the UI. This extra richness is very useful in a business application because it increases user productivity.
Ray Burns
+1  A: 

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.

Icabod
This is fixed in .NET 4 -- see http://blogs.msdn.com/text/archive/2009/08/24/wpf-4-0-text-stack-improvements.aspx
Ben M