Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinForms to WPF - How do we get there from here?

Is there a practical way for us to slowly evolve a WinForms application to WPF without creating a support nightmare for ourselves with strange interop scenarios?

Background info:

We have a large battleship gray WinForms application that is heavily used by an internal group of about 60-75 users. We're starting to run into places where we could see some benefit from having the app in WPF, but it's not enough to justify a large project to completely re-write it. All of the screens in the app are self-contained WinForms user controls and the WinForms app is just a shell that handles menuing, opening/closing forms, provides some shared helper methods, etc...

Thus far, the best idea we've had is to convert the shell application to WPF and then host the WinForms user controls inside it. We thought that we could then convert the user controls over time, tieing those changes to initiatives that have enough business value to support the additional work. I'm concerned about how well the interop works and how it will impact performance. I'm also concerned about how we transition to a new look for the app. It would seem odd to make the shell app look snazzy and then have old battleship gray user controls hosted inside it and it also seems odd to create the shell app in WPF and make it look just like it did in WinForms.

If one of the Caliburn, Prism, or another similar framework would ease the transition, we'd be open to exploring those options as well.

like image 691
Paul G Avatar asked Aug 11 '10 11:08

Paul G


People also ask

How do I convert WinForms to WPF?

1) Target a certain part of your WinForms that you would like to switch up to WPF and then take it out. 2) Replace it with ElementHost. 3) Then in that ElementHost you will have your newly rewritten WPF counterpart. 4) Test it out make sure that it works okay with the rest of the elements.

Is it possible to use Windows form in WPF?

If you wish to use multiple Windows Forms controls in a WPF application, each control should be inside a WindowsFormsHost tag. In previous steps, we created a ListBox control in XAML. You may also create the control dynamically using Windows Forms classes.

Which is better WinForms or WPF?

Winforms vs WPF both are mainly used for the same purpose for developing and designing windows applications, but WPF can be used for the web application. The difference between them is scalability, performance as WPF can render fast compared to windows forms, complexity, and support.


1 Answers

We were in a similar situation and chose the following path: At the beginning we started to host a few WPF windows in the application shell (still WinForms). Of course there was some visible difference but we reduced the difference deliberately by toning down the new windows. We figured that by the time we would convert the remaining windows/controls it will be easier to "upgrade" to a more vivid experience since the UI will be entirely WPF and we can involve a graphical designer to work their magic based on XAML.

We have now reached the point where the majority of the windows are WPF. We have started the process of converting the WinForms shell app into a WPF based shell application hosting the remaining WinForms. We sill have sort of dull colors but users have started to notice the difference and although it is small our users still like the incremental positive change. Not too long and we will retire the last WinForm. That will be the point when we let our graphical designers off the leash!

As to performance: I can certainly not make a general statement as it heavily depends on your particular controls/windows. In our product (several hundred windows) we haven't found any significant performance issue related to the mix of WPF and WinForms.

We didn't look into any of the frameworks, so I'm afraid I cannot comment on those.

like image 140
Manfred Avatar answered Oct 05 '22 06:10

Manfred