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?
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.
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.
Yes you can, both Windows Forms within a WPF application, and WPF controls within Windows Forms.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With