Example of a winforms app implemented as a wpf app?
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?
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.
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.
Have a look at the WPF futures on CodePlex here http://www.codeplex.com/wpf/Release/ProjectReleases.aspx?ReleaseId=14962 and grab the WPF Model-View-ViewModel Toolkit 0.1
Installing this gives you an MVVM template in visual studio that you can use to create a new project.
This is a good starting point for creating a WPF application using MVVM. The basic premise to remember is that wherever possible the View (UI) and the ModelView should communicate solely through data binding.
I found this template really useful whilst I was trying to get my head around WPF.
链接地址: http://www.djcxy.com/p/29170.html