21

For a brand new application, is it better to use WPF over Windows Forms? I used Windows Forms before but not much WPF. As far as I know, WPF is the successor to Windows Forms, right?

The application is going to host DirectX Windows (not WPF 3D, but Managed DirectX and SlimDX) with lots of custom controls.

EDIT: The application is a 3D related application, editor, such as modo:

Image created using the 3D painting program modo.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Joan Venge
  • 315,713
  • 212
  • 479
  • 689

11 Answers11

19

We dealt with this question about 9 months ago. We decided to go with WPF and so far we're happy with the decision. Yes, there is a learning curve. It's fairly considerable especially coming from WinForms where you have so much to unlearn. I also recommend you have access to a designer otherwise your application will probably look a bit shabby. Also be prepared for some WPF gotchas that will have you spending hours scratching your head saying 'why was this so hard'.

But WPF is a step ahead. The data binding, templating and complete control of how you want your windows to look makes you think that this how WinForms should've been originally.

Oh yes, and be prepared to shell out a couple of dollars for some missing controls. There are a couple of things missing like a Date picker and having checkboxes on tree controls (you can actually template this out, but it's not as simple as winforms in that regard). 3.5 SP1 includes a grid control now, thankfully.

I'm sure I'm missing a bunch more, but that's what I can come up with off the top of my head.

Good luck!

billb
  • 3,608
  • 1
  • 32
  • 36
  • Both the DatePicker and DataGrid are part of the WPF Toolkit, which requires .NET 3.5SP1. http://wpf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=22567 – Andy Mar 12 '09 at 22:28
  • Update: WPF now has lots of new controls see http://weblogs.asp.net/scottgu/archive/2009/10/26/wpf-4-vs-2010-and-net-4-0-series.aspx – gideon Jan 13 '11 at 03:45
17

I know this is an old post, but I think it's still a valid question.

I used WinForms for 3 years at the first company I worked for. There were some really good programmers there, and they found some very clever ways to do some very cool things. WinForms has stood the test of time. It is a solid, reliable and efficient platform. Many people, and many companies both large and small have been using WinForms for years, and the technology has proven itself time and time again. Inertia like that is hard to fight, even if you are Microsoft.

Still, WPF is definitely the future. Microsoft made that clear by making products such as Visual Studio 2010 and Expression Blend with it. (In using WPF for internal projects, Microsoft was forced to fix many of the issues, such as font rendering and speed issues, that prevented people from adopting it at first. Visual Studio 2010 shows that WPF has long been ready for production.

So, is it better to write your program in WinForms or WPF? The answer is this : WPF. I say this for two reasons. Firstly, because Microsoft is supporting it internally, we can assume that it will be around for a very long time. Microsoft has shown us that it is the next tool of choice which leads me to my next point: it has become superior to WinForms (some people I have spoken to disagree, but it is the truth nonetheless, and is becoming more obvious every day). WPF has a host of features that WinForms will (probably) never be given, such as integrated support amazing data binding, and timeline based animations that make it easy to make amazing themes for your apps, and will have designers begging to make the switch. There is much more to WPF than can ever be described in a comment, but these are two big ones for me :)

This being said, I know there is nothing you can do in WPF that you cannot do in WinForms. You can do anything in any language if you want to badly enough. The point is that where WinForm's will leave you scouring google for how somebody else did something cool, WPF ships with built-in support for all the features that Microsoft considers to be the future of Windows and puts them right at your fingertips.

Over time, people will become used to new features build directly into Windows, and will come to expect them to be available in all the applications they use. This will reach the point where anything that doesn't support them will feel clunky, less usable, and seem less worth spending money on. (I see Touch integration as the most obvious example of this. Although there are touch screen solutions that clamp onto a monitor and emulate a mouse, on any computer, touch screen technology has come a very long way, and with Windows 8 blurring the line between the desktop and mobile devices, people will likely want to use applications in a way that will be exceptionally difficult to implement if your application uses WinForms.)

Sooner or later, I believe that support and development for WinForms will stop, and everybody that left themselves behind will be forced to port, and quickly. However, there are too many programs out there that rely on WinForms for Microsoft to be able to drop it in the near future. Who knows what will happen. Perhaps WinForms will be to Microsoft what Itanium Processors are to Intel, the product that has enough users that to keep it going, even though there are better solutions available. ( http://arstechnica.com/business/news/2011/06/ask-ars-why-itaniumask-ars-with-xeons-improvement-why-bother-with-itanium.ars )

So my advice would be this: regarding new development, make the switch to WPF. Send some staff on training courses, or let them play for a while so they can get a better feel for the technology. The learning curve is going to be steep, but doing this will increase your team's skill set because by learning WPF, they will also be well on their way to learning SilverLight, which is similar enough to WPF for people familiar with WPF to be be able to learn it quickly, but is designed for the web rather than the desktop. This is valuable because apps rewritten in WPF will far easier to convert to Web Apps later down the line. WPF is new, but it was made for a reason, not simply for the sake of making something else for people to learn. It was designed to make applications more user friendly, intuitive, and portable. It was designed to help developers make their applications fit into the new age of computers.

Regarding applications written in WinForms : I think it's safe to assume that WinForms will still be supported for quite a long time simply because of the amount of support it has gained. I would recommend letting your team familiarize themselves with WPF, and slowly start moving your applications over to WPF. Take all the time that Microsoft allows and don't rush the process, but always keep in mind that, one way or another, WinForms day's are over, and although nobody can be sure what will happen, support for the legacy product will be dropped as soon as it can be justified. Even if WinForms applications are kept around for many years, it is important to remember that times are changing, and we all need to change with them.

Dane
  • 171
  • 1
  • 3
12

----EDIT 2 -----

Given that you're trying to make an editor like the one you showed, I'd recommend going WPF even more. My current project has many features along those lines, as well, and we've decided that the ability to composite WPF with Direct3D content is extremely powerful. It's nice to be able to render your scene into anything - not just a rectangular window. In WinForms, you pretty much were limited to one rectangle, and you had issues with airspace there, too (subtle, but things like flickering issues when menus pull over your hwnd, etc). The WPF compositor with D3DImage gets rid of all of those issues, and lets you use your imagination to construct a very flexible UI. Things like rendering your scene in realtime on the side of a WPF3D object are possible, or using WPF controls directly on top of your d3d scene instead of trying to do the GUI in D3D, etc.

-----Original---------

If you're going to be hosting DX, you might want to consider it - especially since it gives you the ability to do scene composition with your UI and no airspace issues if you use D3DImage.

This does work with SlimDX and WPF.

----EDIT-----

For more information on the disadvantages of using Direct3D with Winforms, and the advantages of WPF/DX integration, see:

MSDN Article on Airspace

Codeproject arcticle on intro to D3DImage

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
6

I found that once I got a handle on Expression Blend and WPF I was more productive at building UIs than with Windows Forms. To my mind that's one of, if not the, biggest factor with a new technology/tool; if you can't acheive the same result as the old tool faster with the new tool then all the bells and whistles, that you only use 10% of the time, won't make up for it.

Apart from that there are other advantages WPF has over Forms:

  • Having the interface in XAML makes it so much easier to fine tune all those obscure properties or to cut and paste a whole section of one control into another,

  • WPF makes it a lot easier to modularise an interface, breaking a screen down control by control. Forms can do the same to an extent but I always found it a battle,

  • Some of the bells and whistles are cool. I've found the use of animations (storyboards) really useful for data entry screens where you need different entry boxes depending on which product is chosen or such. With Forms you'd have to create a separate panel/form for each data entry screen, with WPF I use an animation to hide and move the various text boxes around.

sipsorcery
  • 30,273
  • 24
  • 104
  • 155
5

If you're writing lots of custom controls I would choose WPF. Part of WPF's design is to be extendable, composable and the result is that it's dirt simple to write custom controls.

I've done a bit of custom control writing in WinForms and it can be very challanging at time. Layout will really take some time away from you. Several weekends of my life were paid to WinForm Control Layout. Writing the equivalent controls in WPF was a cinch.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
3

We just went through this too… we started a move to WPF over WinForms. I think that these days it is a pretty easy decision to put WinForms behind you. The tooling is getting better and better and if you can get a true designer on your team there are very few things that you can’t put together.

We are starting to realize that our future is actually not WPF, but it is Silverlight. As Silverlight matures it is becoming more and more on par with WPF and it allows you to run cross platform. The path of Silverlight is more like Adobe Air and one day it will live outside the browser (actually you can do it now, but it is a pain). I really think that the future for .NET UI is going to be Silverlight.

Brian ONeil
  • 4,229
  • 2
  • 23
  • 25
2

In this case, I'd say follow the lead of your Vendor (i.e. Microsoft). Their own internal production increasingly features WPF; and it's scope (think Silverlight) and depth are clearly greater than WinForms. They also use it increasingly with reference to Best Practices. From all the evidence (here and elsewhere), it appears to be ready for Prime Time developement.

You have epressed no particular affinity for WinForms (I would guess what there is is based on familiarity). You'll need to switch eventually. A new project would be a great place to start the process, everything else being equal.

dkretz
  • 37,399
  • 13
  • 80
  • 138
2

Having just recently done a very similar product (3d viewer for mining data in WPF) I can definitely recommend WPF/SlimDX.

The tools are a bit lax (especially Visual Studio), but WPF makes it much easier to make an app with a bit of Zing, rather than the default control grey that most things have.

Using D3DImage from 3.5SP1 it's very easy to host a SlimDX device inside a control.

Overall I'd say WPF isn't better to use, just different. Some things are better, some are worse. But it's definitely the future.

Cameron MacFarland
  • 70,676
  • 20
  • 104
  • 133
2

For what it's worth, it's 2020, and I have written desktop applications in both WPF using MVVM and Windows Forms. I must say that I do not miss writing boilerplate type of code for WPF, such as classes for Converters, using some sort of event mediator to communicate between views, Commands, etc. Using MVVM Light can help with that problem. I like the clean separation of code in WPF/MVVM, but for small projects, I think the ability to very quickly push out a Windows Forms application cannot be understated. For graphic intensive applications, WPF will perform better than Windows Forms.

These days, I tend to lean towards web development when possible since the web is available anywhere there's a network connection. Of course, web development typically has a longer product delivery as well. A positive, is that the C# that you already know, can translate to development in ASP.NET.

iCode
  • 1,254
  • 1
  • 13
  • 16
1

In your case, WPF makes sense. For me, it's an application by application choice because there are a lot of things you can do really well in Windows Forms (like rapid development of business applications). I'm using WPF to write a nice GUI for a media center application (personal project for a media console on my 50-inch plasma screen).

However, if I'm writing a data entry and display application, I typically go with Windows Forms for speed of development. The XAML editor is better in Visual Studio 2010 but still has a way to go. Without a reference there's no IntelliSense help on a lot of the property attributes so it's impossible to know what goes in them (which is where I spend a lot of my time trying to find those values, either through a book or examples on the web). That said, if you do WPF write, you can make some very compelling user interfaces.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
John
  • 11
  • 1
1

AFAIK WPF is the successor to WinForms, right?

I don't believe this is true as much as MS might like to push this. There is just too much legacy code written on Winforms for that to be a realistic thing in the near or even somewhat distant future.

So with that in mind, if you would like to, and can afford to spend the time learning WPF I would do that. Otherwise I would use Winforms.

Dan Blair
  • 2,399
  • 3
  • 21
  • 32
  • Well, Vista was the successor to XP, but it wasn't meant to make all Vista platforms defunct. WPF was and is intended by MS to revamp the fundamentals of WinForms while fulfilling the same niche. – DevinB Mar 12 '09 at 23:04
  • You'll be surprised, I think! – Tor Haugen Apr 02 '09 at 14:42