blog

MVVM for Dummies

Published on
2 minute read

I think that I have found one of the best articles on MVVM that I have ever read:

http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/432/MVVM-for-Tarded-Folks-Like-Me-or-MVVM-and-What-it-Means-to-Me.aspx 

This article sums up what is in MVVM and what is outside of MVVM. Note, when I and most other people say MVVM, they really mean MVVM, Commanding, Dependency Injection + any other Patterns you need to create your application.

In WPF a lot of use is made of the Decorator and Behaviour pattern as well. The goal of all of this is to have pure separation of concerns. This is what every code behind file of every Control / Window / Page  should look like if you are engineering your WPF and Silverlight correctly:

C# – Ideal

  public partial class IdealView : UserControl
  {
      public IdealView()
      {
          InitializeComponent();
      }
  }

Figure: This is the ideal code behind for a Control / Window / Page when using MVVM.

C# – Compromise, but works

  public partial class IdealView : UserControl
  {
      public IdealView()
      {
          InitializeComponent();

          this.DataContext = new IdealViewModel();
      }
  }

Figure: This is a compromise, but the best you can do without Dependency Injection

VB.NET – Ideal

Partial Public Class ServerExplorerConnectView

End Class

Figure: This is the ideal code behind for a Control / Window / Page when using MVVM.

VB.NET – Compromise, but works

Partial Public Class ServerExplorerConnectView

    Private Sub ServerExplorerConnectView_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Me.DataContext = New ServerExplorerConnectViewModel
    End Sub

End Class

Figure: This is a compromise, but the best you can do without Dependency Injection

Technorati Tags: .NET    WPF    Silverlight    MVVM 

code-and-complexity blog code mvvm silverlight ssw tools wpf

Connect with Martin Hinshelwood

If you've made it this far, it's worth connecting with our principal consultant and coach, Martin Hinshelwood, for a 30-minute 'ask me anything' call.

Our Happy Clients​

We partner with businesses across diverse industries, including finance, insurance, healthcare, pharmaceuticals, technology, engineering, transportation, hospitality, entertainment, legal, government, and military sectors.​

Freadom Logo
Genus Breeding Ltd Logo
Big Data for Humans Logo
Alignment Healthcare Logo
Schlumberger Logo

NIT A/S

Qualco Logo
Slicedbread Logo
Workday Logo
Sage Logo
Kongsberg Maritime Logo
Capita Secure Information Solutions Ltd Logo
New Signature Logo
Akaditi Logo
Xceptor - Process and Data Automation Logo
Emerson Process Management Logo
Ericson Logo
Bistech Logo
New Hampshire Supreme Court Logo
Ghana Police Service Logo
Washington Department of Enterprise Services Logo
Nottingham County Council Logo
Washington Department of Transport Logo
Department of Work and Pensions (UK) Logo
Lockheed Martin Logo
Brandes Investment Partners L.P. Logo
ALS Life Sciences Logo
Boxit Document Solutions Logo
New Signature Logo
Flowmaster (a Mentor Graphics Company) Logo