Convert a Winform application to WPF application

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.


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/


Trying to create WPF controls without XAML is asking for trouble - the whole framework is built around the MVVM pattern which demands that your View be described in a declarative fashion, rather than a procedural fashion. While you can definitely create same UI objects in C# and XAML, doing so in C# will require you to know (in truly excruciating detail) how the framework operates in order to compensate when the state of your UI changes. On the flip side, if you do it XAML (as WPF dictates you are supposed to), then things generally update just fine and without the necessity of working around endless bugs. In short "yes" you can do it in code, but "no" you can't do it in code without losing your sanity.