Click here to Skip to main content
13,868,202 members
Rate this:
Please Sign up or sign in to vote.
I am currently working on a bigger WinForms project. I used to program small applications using WinForms that had a maximum of ~20 different windows.

Now I am facing a bigger project and want to adapt to that by overthinking my approach to that.

I have read about MVVM and MVC and some variations.
Speaking of variations: I found so many variations, that I have no idea which implementation they originated from.

My Idea is that it has:
-easily scalability
-clear seperation of concerns (SoC)
-an intuitive way of usage

Some side-notes on this project:
-Hotkey-driven navigation (every view can have multiple hotkeys to navigate to other views)
-Fast response time required (the client does not like to wait for a query to finish longer than 1 second.)

Below you will see my current idea of how to use a pattern.
I am very thankful for criticism and/or tips on this.
Also I would be very thankful to hear your suggestions on how to use this pattern and if any traps exists how to avoid them.

Thank you in advance :)

What I have tried:

So far I have designed the following pattern as an approach:


void SetViewModel(ViewModel viewmodel);
void Clear();

The View only has to accept a ViewModel class to display.
All logic in the view is for registering key events and button clicks etc.
If something like that happens a event is fired or a command redirected to the Controller.

void AddView(View view);
void RemoveView(View view);
void SetModel(Model model);
void SetViewModel(ViewModel viewmodel);

My controller will contain all decision-relevant logic. (example: If button X is clicked on View - Open new View)
It will accept views (one or many) and update every View.

event PropertyChangedEventHandler PropertyChanged;
T Get<T>(string property);
void Set<T>(string property, T value);

event PropertyChangedEventHandler PropertyChanged;
T Get<T>(string property);
void Set<T>(string property, T value);

Model and ViewModel are almost similar.
They contain the values of the entity and fire events when a property changes.

Converter<TVM, TM>
TM ConvertToModel(TVM viewmodel);
TVM ConvertToViewModel(TM model);

My Converters will be responsible on converting models from ViewModel to Model and back. They will need to handle view-relevant conversions and formatting specific things.

I am unsure how to identify implementation traps and possible faulty design choices beforehand and require some guidance on how to approach a big project with a neat pattern to follow.
Updated 6-Dec-18 9:37am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

DZone has a nice refcard about the original Gang of Four design patterns which you can download for free (after signing up):[^]
I also stumbled upon this article on DZone about the Factory pattern by a well known CodeProjector (Richard McCutchan):[^]
The Factory pattern is one of the most useful I think especially if you want to decouple classes in a big solution.
CursedProgrammer 8-Dec-18 21:13pm
Working through the PDF really helped me with the implementation of the base of the project. Thanks for the link. I accept this solution because it helped me a lot already.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Maybe you can use custom forms, something like this:
public class CustomForm : Form
    /// <summary>
    /// Initializes a new instance of the <see cref="CustomForm"/> class.
    /// </summary>
    public CustomForm()
        // Required for Windows Form Designer support

    private void CustomFormLoad(object sender, EventArgs e)
        this.BackColor = SkinSettings.FormBackgroundColor;
        this.ForeColor = SkinSettings.FormForegroundColor;
        this.Font = SkinSettings.FontDefault;

        if (this.Text == @"CustomForm")
            this.Text = SkinSettings.ProductName;
            this.Icon = SkinSettings.FormIcon;
CursedProgrammer 6-Dec-18 10:33am
Hello RickZeeland, thank you for your answer.

I have tinkered with a similar idea too.

But lets go back to the conceptual question here please:

Apart from the implementation details, do you know an idea on how to organize a big project with such a pattern?
Or do you have ideas on how to modify this pattern to make better use of specific features of WinForms? (e.g. DataBinding)
Gerry Schmitz 6-Dec-18 12:44pm
"Refactor" your "old" project and make it the "template" for your new project (based on lessons learned).

Starting from "scratch" now (again) will have you spinning wheels most of the time.

And being a slave to MVVM (when you can't answer why) makes for a mediocre (herd) app.
RickZeeland 6-Dec-18 13:10pm
I'm afraid I'm no fan of MVC or MVVM, and agree with Gerry that you should not become a slave of such a pattern, but that might be because me and my colleagues have to struggle with a legacy MVC application of a developer that has the left the company and has given us many headaches.
To me Windows Forms is already MVC as the code and form design are in separate files ! But all this might be my biased view of course ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190214.1 | Last Updated 9 Dec 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100