Looking for clean WinForms MVC tutorial for C# [closed]

烈酒焚心 提交于 2019-11-27 06:16:15

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'

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!