views:

5122

answers:

6

How to create a rich user interface Windows application, example Photo Shop.

I am looking for clean MVC tutorial for WinForms with C# somewhere. (Not ASP.NET MVC.)

Being new on the Windows Platform; most MSDN and internet tutorials basically puts everything into the Form class. Further Default events are handled inside of the form, instead of sending events to the control/model, which in it's turn changes the view's state.

Or is the preferred methodology for Windows Applications something else?

+1  A: 

It might be worth looking at the Model-View-ViewModel (if you're interested/happy to use WPF particularly).

It's tweaked specifically to work with WPF and Silverlight, and makes use of databinding in order to glue everything together.

There's a number of resources on the web for finding out more, including John Gossman's introduction, and a good article by Josh Smith, who has other resources on his blog relating to MVVM.

Dave Arkell
Josh Smith's article is really good
s5804
+4  A: 

Take a look at this tutorial. I was looking for the same thing as you and found this helpful. It is Model-View-Presenter but still quite informative.

http://www.cerquit.com/blogs/post/MVP-Part-I-e28093-Building-it-from-Scratch.aspx

Refracted Paladin
A: 

For Windows applications, the Windows OS inadvertently becomes part of the Controller.

The Model can subscribe to various events/ messages (e.g. mouse click, move, window re-size, button click...). When it has done its change-update-processing the view is updated through the redraw operations.

Windows OS acts as the controller here because it is both sending messages to the model (e.g. mouse click) or to the view (telling it a portion of windows is dirty and needs redraw).

Of course for any commercial application, you would implement your own model and document structures and separate them from the corresponding WinForm objects.

In .net this is not so clear because there is only one file for both the model and view portions. In MFC it was very clear - with a CDocument class and its corresponding CView class.

Rather than the MVC pattern, for Windows applications it helps to understand the Windows messaging architecture and how to handle them.

Sesh
Are you suggesting that Winforms are sufficient in most cases. Provided that messaging is done correct?
s5804
Yes. However do think if you have cases like needing to update multiple forms etc. In such case perhaps it makes sense to separate the model into a different class and may be implement a controller as well to coordinate between the model class and the form objects.
Sesh
I disagree with the statement: "For Windows applications, the Windows OS inadvertently becomes part of the Controller." You can still use patterns even if WinForms doesn't mandate a particular pattern (MVC/MVP/MVVM/etc.) Look at the links from balioune_ba and Refactored Paladin for patterns and frameworks. That being said, MVC may not be the best pattern for WinForms and WPF offers a more natural way of implementing MV* patterns.
Ryan
@Ryan, if at least you had read the whole post or the answer to s5804's question.The post says Windows OS is 'part' of the controller. And this will remain valid till the windows.h file that ships with OS has the definitions for windows messages.
Sesh
@Sesh, I did read the whole post but I still respectfully disagree. The controller is what you make of it. If you don't tie the controller to the OS then the OS is irrelevant. It is all about design; that is why MVC frameworks exist on many different platforms, by *not* tying specifically to OS features where possible. Finally, this is C#/WinForms and not Win32 with #include <windows.h>. There are WinForm MVC frameworks out there. If, on the other hand, you mean that the MVC frameworks that do exist for WinForms are Windows specific and not cross platform, that I can agree with.
Ryan
A: 

Hi, You can take a look at these implementations from codeplex

http://koosserymvcwin.codeplex.com/

http://wrails.codeplex.com/

http://winformsmvc.codeplex.com/

Give us your feedbacks.

A: 

Here is some more information on the MVP Pattern.

http://www.martinfowler.com/eaaDev/ModelViewPresenter.html

FernandoZ
+3  A: 

Derick Bailey (via Los Techies) has blogged some fantastic articles (and complete demo source code) for his implementation of MVP in a WinForms app with a couple of other good patterns added to the mix (Application Controller, Event Aggregator).

The work is inspired by Jeremy D Miller's series of articles titled 'Build Your Own CAB'

rohancragg