Should we migrate to WPF or Winforms? [duplicate] - wpf

This question already exists:
Closed 14 years ago.
DUPE: When is Windows Forms the correct choice vs WPF?
We have to decide these days whether or not to go with WPF as a platform for building our next generation of our product.
Personally I am a little afraid of using this technology especially because of performance and because it's not mature (I am not sure about the quality of the UI editors such as Blend).

Personally, I absolutely adore WPF.
It requires a fundamental shift in thinking from Winforms. Winforms you drag and drop stuff on to a form. That gets you 80% of the way really quickly and easily, but when you need to move outside of the things that WinForms explicitly covers, you enter a world of pain.
In WPF, first thing you do is turn off the visual editor. The code for your UI goes from an ugly mess to something beautiful. Also, it is remarkably powerful and flexible, once you get the hang of it the things you can do are absolutely amazing.
The downside to WPF is that it is more heavy then WinForms, and the learning curve is relatively huge. However, it is the way of the future, and unless it is a trivial app you are making, I would choose WPF hands down.

If you don't need a very glossy UI with animations and so on, I see little reason to jump to WPF... just yet.

If you are worried about performance, you should check these MSDN pages:
Windows Presentation Foundation Performance
My guess is that WPF is even outperforming Winforms as long as there is appropriate DirectX hardware because rendering can be done by the GPU directly then.

Considering MS is building their next version of VS with a WPF based code editor, I find it hard to find support for WPF not being 'mature' or having performance issues.
I would say if you are able to migrate anyway, you might as well upgrade to increase the longevity of your code base. If your code is written properly in Winforms, it should not be very difficult to start moving this forward into WPF.

I started about 10 weeks ago teaching myself WPF, and then in the last 2 weeks I have actually written an application in WPF.
I came from ASP.NET and I love WPF. I love the XAML markup, it just makes more sense than dragging items over and making sure they are in the right place in a WinForm.
The styling is easier in WPF, you can quickly make a border with rounded corners.
Using Expression Blend you can design a really nice interface with animation.
I developed a WPF app on Vista (home), and XP (work) and they both look really nice.
I have been very pleased with WPF and would not go back to WinForms.

My sense would be that if you are happy with the look and feel of winforms, then stick with it. If you think you will be doing any visual customization, then go WPF. But then I have been working with winforms for a long time and WPF very little. If I was starting out, I would probably focus on learning WPF since it really is much more flexible

Related

Designing GUI in WPF as easy as Winforms?

I am familiar with Winforms GUI design: drag and drop controls on to the form, write code for the events, etc.
Using VS2010 is creating a WPF app this easy?
Learning XAML is a fairly involved.
stopping using code behind and events from your gui and going to MVVM is an eye opener.
So, if you find winform gui coding "natural", then going to wpf is not going to be overly easy.
It is however IMO well worth it. MVVM gives amazing benefits in terms of simplifying and reducing code.
If you need your controls to do something out of the norm, then XAML and styles are great for customizing your gui.
Yes, it is very easy once you have some experience with WPF. Like anything you'll need to get used to it, and learn the tricks.
For quick, simple, single form projects I think winforms will always be faster and easiest.

Moving from WinForms to WPF

Well we are considering to move from WinForms to WPF, what pitfalls does WPF have? And we got component one's flexgrid is there any wpf grid that has the same functions? one nice thing with it is that you can implement your own draw method for the cells... It can merge cells print and save to many file formats..
In general, WPF development is very different from WinForms. You should expect it will take some time to learn the new technology (or you might even need to hire new developers =)).
WPF approach is in many ways better than WinForms' one: check out styles and triggers, data binding, control templating, eventing model.
I would recommend you to start exploring it, but wait for the WPF 4 (and the boring MSDN page) to start the actual migration, because it is going to be even better and close some of the very annoying gaps.
First of all, WPF works pretty different from Windows Forms and likely requires a different approach on how to structure and design the application. At least it works way better if you do it the way it was conceived.
As for single Windows Forms controls, this shouldn't be a problem. There is a WindowsFormsHost which enables you to include Windows Forms controls in WPF.
The change from winforms to WPF is not a change I'd reccommend unless you have specific requirements which WPF fulfills - WPF is not intended to be a replacement, simply an alternative which is more suited towards graphically rich applications.
If you do have a specific requirement then you also might want to consider embedding WPF controls into winforms applications, rather than converting your entire application.
The learning curve is slow to get going, but once you get the idea it all starts to make sense. We have "Pro WPF in C# 2008" book floating round the office and its been a great help. Of course most things get googled to find an answer, but to find out why something is done the way it is this book was a great hope - to me anyway.
There are some annoying features but its still WPF is still quite new. Like most things, if you come across a problem someone has likely come across it before and there is an answer out there!!
J
Take a look here for a datagrid: http://wpf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=29117
The main hurdle with WPF is simply the huge amount of new stuff to learn (if you wish to use it properly). I'd think twice if you're on a tight schedule, but it might be worth it if you have 6 months to spare...
Speaking from just my experience, moving from Windows Forms to WPF took some re-learning. A few months into the transition most changes made total sense. WPF removes much of the frustration associated with using Windows Forms. It allows for a truly rich UI development experience especially when working in tandem with designers. I strongly recommend WPF Illustrated by Daniel Solis as a learning aid.
With reference to the grid, Syncfusion offers a WPF grid control that implements the features you have asked for. It implements true virtual mode with cell level customization, printing and export to multiple formats including Excel. Disclaimer - I work for Syncfusion.

What can WPF do and not do?

i've been learning wpf for about a week now..
and i have a basic question:
From a business view and development view (out of your experience).. what can and what cant be done with wpf(capabilities) ..
please try to be illustrative..
examples of undesired answers:
"Fully functioning stand alone applications with alot of animation and Glittering images"
A second question:
if i build a XBAP UI for my application, can i make the UI "not show" in a browser!
if u r going to answer from tutorials/websites/books.. please dont copy paste them directly, try to write it in your own words...
You can host anything built to the Win32 GDI/USER API (WinForms, ActiveX controls) inside a WPF application, so even if you hit some limitation with an app that is mostly WPF, you can always host some old controls inside it.
And since 3.5 SP1 you can even host animated DirectX graphics pretty seamlessly as well (although WPF's 3D support provides its own much simpler ways of achieving the most commonly done things).
As for comparison, the major advantage of WPF over WinForms is the way it keeps closely to its own component-based model, so a very large proportion of controls are able to act as containers for other controls. Want to put a combo box in a menu item? Not sure why you would, but you can. More usefully, you can put a button in a list box (or tree view). These kinds of thing are not possible unless you implement every standard control from the ground up (which is what WPF does).
The disadvantages are probably temporary: it can be a little unstable on some machines (the rendering code seems vunerable to display driver incompatibility) but this gets better with each service pack. Also the text rendering has been heavily criticised - it goes a bit further with ClearType anti-aliasing than Windows normally does, so some people complain that it looks blurry.
(The reason these are likely to be temporary issues is that Microsoft's Visual Studio 2010 is adopting WPF. So they are now "eating their own dogfood".)
You can pretty much do anything in WPF that you'd need from a GUI app. But that's not the real benefit, IMHO.
One of the real benefits of WPF is development speed and simplicity, once you get past the learning curve (and there is a learning curve!)
The other major benefit, and probably the biggest one, is that it allows designers to work on the presentation, do lots of interactive things, all using a designer-friendly (friendlier, anyway) tool and not having to submit requests to the coders. Just by changing the .xaml, a designer can make an application look almost completely different, and add all kinds of behaviors (panels disappearing, expanding, all kinds of neat stuff). Without changing a line of code.
You can in theory do anything in WPF what you want. Compare it with a WinForms application. Is there anything that you can't build with that? Not really. The same goes for WPF. It's just that WPF is better suited for some things, like animations, video, graphics, etcetera. As it is xaml based, it is also better suited for databinding against XML for example.
See also this related question.
As for your second question, I'm not sure what you mean by that. Do you mean if you can show websites using WPF? Yes of course, just like WinForms.
Oh, in WPF some things are still not implemented. DataGridViews as popular example are only in the codeplex preview. YOu have alot of things like theExpander which work in a differnet way, and you can have a lot of problems with autosized content.

Migrating from Windows Forms to WPF... was it worth it?

I also have a desktop application written in Windows Forms that is a middling size (a couple dozen major forms backed by 46 tables in the database). I'm thinking about rewriting the UI in WPF, but before I go there I was curious if there were any war stories about doing such a conversion.
I use LLBLGen to generate my low level data access objects, and I have a business logic layer above that. The forms are databound to the business logic objects, although the main form uses caching objects to minimize round trips on the more common navigation routes. The UI never speaks directly to the database: always through the UI -> business logic -> low level -> datastore path.
One control that I use heavily is the TreeView, which acts as a visual guide and short range navigation tool. The tree has been heavily customized with icons, highlight colors and it is the control I worry most about porting.
Is there a story that might convince me to go ahead and convert (or conversely, wait until Microsoft is closer to pulling the rug out from under Windows Forms)?
EDIT: I was asked in a comment what motivation for conversion I have. I have some concern about future proofing: I have 500,000 lines of code that were originally ASP and VBScript. We have been porting the functionality over time to ASP.NET and C#, but only as we make changes to the code. The upside is we have kept costs minimized, the downside is half the code remains ASP and VBScript. I'm concerned about a similar situation arising with Windows Forms applications.
Am I worried today about Windows Forms going away? Not even close to it... but the application is moving from ASP and VBScript to ASP.NET and C#, has nine years of history behind it, and probably won't be replaced this decade (instead, simply it will evolve). The desktop application is likewise a long term project with years of history.
For me, the WinForms vs. WPF decision is a simple one - if normal people are going to use it, the user interface can make the difference between a winner and a loser.
It is definitely a steep learning curve. But I have NEVER gotten done with a nice looking WPF application and said "Man, I should have used WinForms".
I'd say invest in the effort to make your UI better whenever possible for your customers, so yes to WPF if that's the case.
WPF has a ridiculously large learning curve. It will most likely require you to rewrite a lot more than you think for just changing the UI. Also, a lot of features that would make WPF nicer to use just aren't implemented or included in WPF yet. Unlike routeNpingme, I have written nice looking WPF applications and have said, "What a waste of time, I should have used Windows Forms and completed in 70% less time".
EDIT:
Also, unless Microsoft figures out a way to make WPF easier to learn, I don't see it catching on to the masses at all. WPF can do some very cool things, but a little effort to make it easy to understand instead of throwing stuff over the wall would have gone a long way. It would not surprise me in the slightest to see Microsoft drop WPF for something easier to work with in the not too distant future. So don't go changing your Windows Forms application just for the sake of changing it.
Pros:
Ridiculously easy data-binding (most of the time)
Ridiculously easy customization of look and feel
Cons:
Very steep learning curve
Some obvious bugs or issues. Similar to .NET 1.0 Windows Forms
Little or no tool support
In my opinion, WPF will definitely replace Windows Forms at some point. However, right now the tools are the main thing keeping it back. I disagree with Dunk that Microsoft will drop it for something else. Change it yes, but I think it's here to stay.
Should you change your application to use WPF now? No. Feel free to learn WPF but if your application works fine currently, then WPF won't give you anything extra. It just makes doing what is possible in Windows Forms much easier.
WPF is great. It is particularly good for extending controls like TreeView with customisations. You can add a string as an item in a TreeControl. You can also add a small panel containing an image and some text in various fonts and colours. Or you can add buttons, or anything you like. It has a completely general composability system. Same goes for ListBox, ComboBox, Button, etc. All their content or child items can be as simple as a string or as complex as a multipage document viewer with zoom buttons (if you want).
But the only way to find out is to try porting one of your forms. It shouldn't be too hard to make a WPF Window open from within your existing app. I started using WPF by making new GUI panels that were hosted inside a C++ Win32 application. Eventually it was so obvious that WPF was the way to go that we switched it around and made the outer shell WPF, with some ancient dialog boxes still implemented by the old C++ code where we couldn't be bothered to rewrite them (probably exactly what will happen with Visual Studio 2010).
Porting is a tough decision. So just some thoughts to help you decide.
WinForms is OK while you work by the rules and keep everything drawn as is. But even redrawing a border on some controls may require complex and precise work and skill, as you already know from tree customization. The same tasks can be done in a very elegant way in WPF.
Also, the data-binding in WPF saves me a lot of time. In the long term, you end up thinking about data-binding scenarios that could not be remotely possible in WinForms without special-case coding.
I do not even consider WinForms for new development -- there is no excuse for customization costs.
I have started introducing WPF elements within my WinForms application and so far have had a lot of success.
The application's main component is a grid control and I haven't yet found the text rendering of WPF sharp enough to present a table of important textual data.
But the application has several additional panels, and the majority of these are implemented using WPF. So, I'm going for a hybrid of WinForms and WPF via the ElementHost control.
I have found the flexibility of WPF to allow for a much more attractive and usable UI, and my users seem very happy with it. In my case, it's also been politically easier to introduce WPF one panel at a time.
WPF's main value to me is in the binding, not in the cooler UI. The worst WPF I've ever seen is when people use WPF just because it's newer, and put all the work in the code-behind, including not using binding. What you get is WinForms data management. So be sure you're going to use the wonderful binding when you do WPF.
I would port the OP's business logic to a business layer for ease of maintenance and conversion. I wouldn't port the WinForms to Xaml at all unless new Xaml functionality was needed, and preferably not until after the functionality was ported.

Is knowing blend required?

Do you expect your WPF developers to know expression blend?
Any good resources for learning more about Blend?
[UPDATE] Does knowing blend make you more productive?
I found Blend a great way to ease into XAML. Many of the common things you want to do are easy in Blend, especially databinding. Databinding has no intellisense and I found doing things in Blend a great way of discovering how do write the databinding syntax.
I now find myself mostly editing raw XAML buy hand.
The areas where blend is really handy:
Customizing templates.
Animation
Breaking the UI down into user controls
As a WPF developer I surely see the benifit of knowing Expression Blend for many of my previous projects. This help me to jump start on creating Usercontrols and Custom controls very effectively. And if we do in the conventional way of writing XAML from the scratch, it is gonna take a very long time of your development.
And also for creating DataTemplate,ControlTemplate,Styles and ItemsPanelTemplate - it is just a click away in Expression blend.
So I highly recommend Expression blend for a WPF programmer
I typically work in both blend and Visual Studio (2005) side by side when doing WPF development. (Although, granted, I typically do both design and c# coding).
The benefits of using Blend is that certain tasks are extremely fast there - things like picking colors/brushes, creating animations and layout fixes such as tweaking margins/paddings.
Another usage is to instantly see how your hand written XAML will look like without actually starting the app.
Blend has a bad habit of producing some weird XAML so I always have to clean it up in the VS text editor afterwards. I still find it to be a net win to use blend though.
So, to answer your question: Is Blend required? no, not really. But it will make your life easier for certain tasks and thus make you more productive.
Things like animation and gradient color definitions can really only be done effectively in Blend. Blend is also often extremely useful for generating some non-trivial custom visual elements, just so that you can view the generated Xaml and import a CLEANER version into your production code. Unfortunately, the point-and-click nature of Blend disguises the fact that huge volumes of very messy Xaml is being generated under the hood, and you'll want to REFACTOR that Xaml before using it in your production source. Fortunately, learning Blend is not that hard. The best tutorial I ever found was called the "Fabrikam" tutorial. There may be updated versions available, but one version of that tutorial is still available at the link below.
http://blogs.msdn.com/expression/articles/516589.aspx
Realistically, very few dev. shops have access to qualified "interactive designers" (its not somethiing a company can just re-task one of its junior Mar-Com people to perform), which means, at most places, developers will need to learn some amount of Blend if marketing wants to add the kind of fancy visuals that provide alot of the justification for using WPF in the first place.
As a developer, after working intensively with WPF for several months, you will find yourself becoming totally comfortable editing Xaml directly and, unlike with Windows Forms, you'll rarely rely on features in the VStudio designer. Not only is direct editing MUCH faster than scrolling through property lists, but VStudio does not have point-and-click support for many of the features you will use in production WPF applications (they just got around to adding an "event" tab in SP#1). Blend has more support for many of these items (it can generate a DataTemplate, for instance), but I usually only jump into Blend to create a quick animation or other visual effect, cut and paste a carefully-refactored version of the markup into my "official" VStudio project source, and move on.
I think at least the designers should start using the Expression Suite.
The developers should be somewhat familiar with the tools but just enough to enable them to communicate better with the designers.
Since there are not so many good WPF tools, knowing Blend is a pretty useful skill. However I wouldn't consider it as requirement. The whole idea of WPF is to distribute work between coders and designers. IMO developer is not required to know Blend throughout, but basic skills are required to understand designer's needs.
Video training for expression blend:
Total Training Expression Blend
http://expression.microsoft.com/en-us/cc136536.aspx
http://windowsclient.net/learn/videos_wpf.aspx
I (as a developer, not designer, soo not designer) tried to start learning WPF through Blend. While I could get stuff working, looking back at what I produced makes me shiver.
Now that I know my way around WPF pretty good, I still use Blend and Design every now and then, but my work is based in XAML (not designer view in VS, mind you, but XAML). In other words,
I know how to clean it up now.
I'm still wondering how I can get my Adobe-Flash, -Photoshop, -Illustrator design guru to work with me in WPF.
It fully depends on what you want to do. To answer your second question, would you really want to try editing an animation storyboard outside of Blend? If you're working with the actual Visuals of the application, Blend is best suited for this. If you want to hack around with databinding, validation and other things where you must swap back and forth with code. Obviously its more sense to work on the XAML in Visual Studio.
Lynda.com has some cool expression blend training available online...
Getting Started with Expression Blend by Lee Brimelow
Developers don't need to know Expression at all.
What you do need to know is XAML and not hide behind some tool, which would be the worst thing you could do as a WPF developer. Your tool of choice is yours to decide on. I used to use the XML editor in Visual Studio.
The only persons who need to know Blend are the ones in charge of the visual aspect of your WPF application. They have to be able to understand how to skin your application with templates, but other than that, they can keep to Blend exclusively.
In general, I think it's more important to for developers to understand XAML, as Blend is just a view on top of it. XAMLPad may be more useful for learning XAML in the first instance.
More specifically to this question though, I think if developers are working alongside designers using Blend, it could be very useful to know at least the basics. As well as allowing better communication (as mentioned by #kokos), it will let the developer perform minor edits (such as alignment etc.) in the same environment, and also understand the limitations and boundaries of the tool with respect to the code generation.
Historically, designer tools have had a few quirks that developers have had to work around, such as re-coding HTML in FrontPage, or generating font tags instead of using styles or classes. I'm sure Blend wouldn't do such things, but it might generate XAML that the developer would prefer to restructure or slim down, so knowing which features generate which styles of code could be very hand for the developer.
Would you require your HTML developers to use DreamWeaver?
All good WPF coders should know XAML by hand and only use tools like Blend for quick mockups, for doing animations or tweening, or for doing complicated gradients, etc.
Coding XAML by hand is a requirement for good WPF developers - Blend is a tool, not a substitute for knowing XAML.
Brennon Williams new book should also be good!!!
(source: pearsoned-ema.com)

Resources