How to implement chat application in C# MVC?

.NET Framework: How do you implement the model-view-controller (MVC) pattern for a desktop application in C#?

  • I am mainly developing web applications using Yii framework. Now I have a C# desktop application project, and I am a little bit confused how to separate model, business, view logics in desktop appilcation. Is there any additional library (framework) to use for this purpose? If not, what is best practice to do it?

  • Answer:

    For a desktop app, WPF  nicely abstracts the MVC pattern for you. You use XAML for Views, Data binding provide Model concept and event handlers provide control. If you building for windows 8 store apps, they follow the same MVC philosopy too. http://msdn.microsoft.com/en-us//library/ms754130.aspx

Chirag Gupta at Quora Visit the source

Was this solution helpful to you?

Other answers

You should use WPF and apply the MVVM pattern. This is the article that introduced it to the world: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx You can find a lot of interesting MVVM-related articles in CodeProject too.

Cesar Leonardo Blum Silveira

As I know the winform applications also used the MVC thought. Details as follow(If you use Visual Studio or Microsoft Solution): (1) Model and View layer     Silverlight/WPF/Winform Control (2) Control or Action layer     Code behind    I think when creating Winforms apps you don't really need much of a framework. That might explain why there are no high profile frameworks in winform.

Changqi Cai

Several people have pointer out that you should use Mvvm and not Mvc - and they are entirely correct. What they haven't said is _why_. A web application is stateless, built around asynchronous requests and responses. A desktop application is not. The "client" and "server" in this case is the same context. The OS will constantly bombard you app with messages about what the user is doing ( pushing buttons, moving the mouse, etc.). So - instead of having a controller push models to views, you have an additional model: The viewmodel. This represents your view in a non-visual way, and is bound directly to the view. Labels and text boxes are bound to properties, buttons to commands, etc, and any change on one end will cause the other to be instantly updated. WPF is designed with this pattern in mind. As a rule of thumb: If you have code-behind on your XAML-files you are doing something wrong. Simply assign your viewmodel to the window's datacontext-property and do everything there.

Christian Ruud

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.