Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of a winforms app implemented as a wpf app?

Tags:

I'm trying to learn more about WPF and I've read a bit about Model-View-ViewModel (MVVM) but if I were to create a WPF app I think I would still do things, out of habit, the same way I did in winforms. Which from my understand is going to eventually code me into a corner.

So to one way for me to learn the 'right' way is to compare and contrast an existing, simple winforms app that is also (correctly) implemented in wpf.

I'm not looking for anything complex, maybe just a couple of forms and a few controls. Does anyone know of simple any examples like this?

like image 558
Gern Blanston Avatar asked Jun 30 '09 23:06

Gern Blanston


2 Answers

Check out this video. He goes through the typical Winforms thinking and then converts it to the MVVM pattern in WPF. Source code is also available.

like image 133
JP Alioto Avatar answered Oct 12 '22 05:10

JP Alioto


For starters, I'd suggest creating a test WinForms project, and a test WPF project. Then add a button and a textbox onto each of the forms and compare the "Designer Generated Code" in the WinForms app to the XAML in the WPF app.

Then you can double-click on the button in the designer window in both projects, and VS will create an OnClick handler for your button in WinForms and in WPF. This will allow you can compare the event handling features of both platforms.

Another common problem we run into when we first delve into WPF is this one:
XAML - get user control position relative to whole window as binding property
You'll learn really fast that there are a lot of simple things, like location, that we are used to doing in WinForms, but that are no longer available to us in WPF.

Apart from this, I'll just add that the biggest learning curve with WPF is the fact that the design sequence is completely reversed from what we are used to. In WPF you are expected to created all of the inner workings of your application first, and then bind that code to the user interface second. This will help keep you from coding yourself into a corner like you mentioned, more than almost anything else.

like image 32
Giffyguy Avatar answered Oct 12 '22 05:10

Giffyguy