Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a Winform application to WPF application

Tags:

I have a little program which I made with WinForms and now I want to make it again using WPF.

I'm new to WPF and I read that whatever you can do with XAML, you can also do without it, meaning using code only.

Of course that you don't have any XAML when using Winforms. Can I use the same code for the WPF application that I used for the winforms application and get the same result? Or do I need to create and edit XAML? What are the advantages of using or not using XAML?

Also, considering the past experience using Winforms, should I somehow change the way I'm thinking about design and implementation that worked for Winforms but are not that appropriate for WPF?

like image 670
Yonatan Nir Avatar asked Sep 23 '13 21:09

Yonatan Nir


People also ask

Can you convert WinForms to WPF?

No you can't reuse code from winforms in WPF. and even if you could, you shouldn't. You should really use XAML to define the UI, and then use DataBinding and MVVM, which is a much more professional way of development than the traditional procedural winforms approach.

Which is better WinForm 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.

Can you mix WPF and WinForms?

Yes you can, both Windows Forms within a WPF application, and WPF controls within Windows Forms.


2 Answers

No you can't reuse code from winforms in WPF.

and even if you could, you shouldn't.

whatever you can do with XAML, you can also do without it

You should really use XAML to define the UI, and then use DataBinding and MVVM, which is a much more professional way of development than the traditional procedural winforms approach.

Not using XAML is much more troublesome than using it. It may look intimidating at first but it's a really awesome thing to work with.

Of course that you don't have any XAML when using Winforms

No, of course not. winforms is a really old technology that doesn't support anything. That's why they created the Visual Studio designer, otherwise no one would have ever used winforms for anything, because of the horrendous gargantuan behemoth amount of code required to do anything useful.

Can I use the same code for the WPF application that I used for the winforms application and get the same result?

Probably, by adapting some class names and whatnot, but then you lose the main advantage provided by WPF, which is precisely getting rid of the horrible winforms-like code.

considering the past experience using Winforms, should I somehow change the way I'm thinking about design and implementation that worked for Winforms but are not that appropriate for WPF?

Yes. WPF supports MVVM, and that requires a really different mentality from the traditional winforms approach.

I strongly recommend reading Rachel's Excellent Post about upgrading from winforms to WPF.

like image 119
Federico Berasategui Avatar answered Sep 30 '22 19:09

Federico Berasategui


I tried converting a Winforms app to WPF directly, and it causes way more issues than you need because you are fighting the framework all the time. Read up on MVVM and databinding and use that. Its what WPF is designed around, and comes with several advantages such as testability. You can actually get quite a long way with a few of the simple concepts (databinding, viewmodels etc...) and expand your knowledge as you go, but I'd recommend an understanding of MVVM and databinding in WPF first.

A good framework to get started with would be MVVMLight, but its worth writing the basics without a framework to get to know how things work first.

I seem to remember this being a good set of posts from reed copsey: http://reedcopsey.com/series/windows-forms-to-mvvm/

like image 40
gmn Avatar answered Sep 30 '22 17:09

gmn