how to create windows application with mvc - c#

hii is it possible to create windows application with mvc

MVP (Model-View-Presenter) and MVP-VM (Model-View-Presenter-ViewModel) is used most often with WinForms.
See SO question: MVP examples for Windows Forms
Dan Bunea's Blog Post: Model View Presenter
Jeremy D. Miller's Blog Post: A Simple Example of the "Humble Dialog Box"
Referance: Mitch Wheat

MVC the pattern: definitely yes! That's platform independent, really.
See some resources:
Looking for clean WinForms MVC tutorial for C#
Selecting a MVC/MVP Implementation for a Winforms Project
Mvc for Winforms - Mapping the View event to the Controller action

Keep only user interface code in the Form object(s). Any interaction between the UI and the data or manipulation of the data should go in its own controller class(es). The domain objects or the data itself is the model.

Read the http://www.objectmentor.com/resources/articles/TheHumbleDialogBox.pdf but you may want to look at WPF and MVVM

Related

Are MVC Partial views like WebForms Controls?

Ok, the question title doesn't really reflect the question that well. But here it is in all it's glory.
I am currently making the transition from WebFroms to MVC as everyone seems to want it without really knowing why. Office politics aside.
Am I right in perceiving that a partial view is "like" a webform control in that it is an almost self-contained unit that adds to the overall _layout? IF not - could you please tell me the point and rationale of Partial views - where to use them, when and why?
Sorry not the best explanation - but it is kind of confusing for me, so it's not suprising that my question is confused as well :P
Thanks in advance.
In the web forms philosophy controls are hold UI part and some backend logic, so you can create a combobox control which always display the list items from some DB table with special stile for e.g. always in red rectangle with blue background
In the MVC philosophy partial views just an a view part, so according to the example above particular view will hold only UI component, the rest of the logic (data provider) should be in the controler's action.
MVC decouple UI from data providers, so you can create other view which still can work with previous defined data provider (action) and vice versa you can use the same partial view (view) for other data providers (actions) which have some interface
In a typical win form, you have a form that contains a few custom controls, each custom control implements part of a whole business logic, when the custom control wants to talk to each other, they will pass data across via presenter. Also, each custom control is a combination of windows standard controls(button, label, textbox,etc). In such case, you can think that each standard control is a html element, custom control is partial view, the whole form is a view and presenter is action method + ajax call.
MVC and WebForms are both programming models.
Comparing partial views to Webforms is not comparing apple to apple.
You have to think different when it comes to MVC or even forget about the WebForms
The closest thing to a partial view in webforms would be master pages in my opinion. And that is just the aspx markup aspect (View) of it.

General WPF Application

Am just creating myself a WPF application, like outlook. am having all forms seperately. I just want one main window and and am haivng navigation pane in left side. when ever i click items in pane, i just want to load corresponding form to the main window in right container. How i can do this?
Use a design pattern like MVP or MVVM..
Also you probably want to use the Command pattern which will benefit the maintainability of your UI related commands.
Tutorials:
WPF Patterns
This tutorial should get you started with these patterns. Paul Stovell shows how to implement MVP and MVVM and displays strenghts and weaknesses of each pattern.
OutlookBar:
This link should get you started with the UI part of your challenge. It shows how to use such a control and implement the Command pattern.
HTH

MVVM like wizard

I am currently building an MVVM based application. The application should also have a wizard in MVVM style. The wizard is not a normal wizard, its a particular kind of a wizard. My goal is to implement a wizard with
1.) has also multiple branches. The wizard can guide you in other direction. So the wizard must not be straightforward.
2.) can also have short cuts. You can skip some pages where default values are setted.
3.) is also normal - straightforward.
Note, some information in the wizrad pages are on-the-fly. That means, that the information can be passed between each step and processed.
Are there any approaches like patterns to solve my problem? How do I implement it the best way?
Did you read this good article in Code Project about Wizard in MVVM and written by two MVVM guru:
http://www.codeproject.com/KB/WPF/InternationalizedWizard.aspx?display=Print
You might have a look at the ViewModel sample application of the WPF Application Framework (WAF). It shows how to implement a Wizard in a MVVM way.
If your wizard has a single VM that stores the state/results of each step and sits behind a view that is a user control...
You could have a Frame on the wizard view that requires 2 events in the code behind (This obviously depends on if your MVVM architecture can live with this?).
Event 1) When the binding of your wizards step raises its NotifyPropertyChanged: tell your frame to "Navigate" to the appropriate page (as described in a property in your wizard VM).
Event 2) On the frames "Navigated" event so that you can point the current pages data-context at your VM.
This way the wizard viewmodel controls the state of the wizard from start to finish and it also can describe the steps, which can easily be added to, edited, etc.
Obviously this may not sit well with everyone's view of MVVM.

MVC in c# win. form application

I 'am building a small windows form application.
I have a View - a simple form that has some functionality in it.
a Controller - a class that will react to loading, saving, getting data from the model and prepare it form the view etc.
a Model - a class that will get and save data to DB or file.
The controller is creating a form instance an run it, and creating a model instance when needed.
I wonder about how to react in the controller to the view events.
Should I register to the view events (buttons click, combo change etc.) ?
This will make the form controls visible outside the form?
Maybe I have a mistake in the design?
Microsoft has created a framework for Win Forms MVC applications, the Composite UI Application framework.
http://www.codeplex.com/smartclient
It is probably overkill for a small project, but you could look at it and get some ideas.
Can you take a look at this SO post
using MVC MVP patterns in winforms
If you google MVP (Model-View-Presenter) you'll find info on how to implement a seperation of concerns pattern in a Windows form application.

Controller/Static State Class in WinForms Application - Where to put?

I'm writing a WinForms application and want to have an "MVC-Type" Design. Actually it's more MVP or MVVM,.
The plan is to have a Central Controller which does all the actual work, so that the Forms just render out ViewModels and handle user input, but everything that actually does something goes through the Controller.
I just wonder if this is a good idea, and where to put the Controller? The current idea is to have a static class which is initialized in Program.cs (Sending in some Dependencies like IMyDatabaseRepository) so that it just stays a controller that delegates work between User Interface and Model.
As you might guess, I come from a Web Background and have little experience with WinForms architecture. Previously, my MainForm was the Controller class, holding all the State Variables, which obviously means that my MainForm is my application rather than just a part of the User Interface.
Nice question Michael!
Here are some links:
Sacha Barber's WPF MVVM VS Project Template
Sacha's Article Series on CodeProject.com
Nice article on this Wordpress blog
Hope these help you to structure your project properly!
I don't know if this is a better way, but I am having Structuremap create my controller and database instance.
The main form has no real code in it - it just loads the first set of controls and then starts the controller. The user controls on the form use StructureMap to access the controller.
My project is regular WinForms and not WPF and is my first time using the MVC pattern with WinForms.
You might have a look at the WAF Windows Forms Adapter download. It comes with the BookLibrary sample application which uses a Controller / MVVM design together with Windows Forms.

Categories