a·gen·tic a·gil·i·ty

MVVM for Dummies

TL;DR; Explains the MVVM pattern in WPF and Silverlight, highlighting separation of concerns, code structure, and the roles of commanding, dependency injection, and design patterns.

Published on
2 minute read
Image
https://nkdagility.com/resources/__7oXNKjdWP
Subscribe

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

1  public partial class IdealView : UserControl
2  {
3      public IdealView()
4      {
5          InitializeComponent();
6      }
7  }

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

C# – Compromise, but works

1  public partial class IdealView : UserControl
2  {
3      public IdealView()
4      {
5          InitializeComponent();
6
7          this.DataContext = new IdealViewModel();
8      }
9  }

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

VB.NET – Ideal

1Partial Public Class ServerExplorerConnectView
2
3End Class

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

VB.NET – Compromise, but works

1Partial Public Class ServerExplorerConnectView
2
3    Private Sub ServerExplorerConnectView_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
4        Me.DataContext = New ServerExplorerConnectViewModel
5    End Sub
6
7End Class

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

Technorati Tags: .NET   WPF   Silverlight   MVVM

Smart Classifications

Each classification [Concepts, Categories, & Tags] was assigned using AI-powered semantic analysis and scored across relevance, depth, and alignment. Final decisions? Still human. Always traceable. Hover to see how it applies.

Subscribe

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.​

Graham & Brown Logo

Graham & Brown

Epic Games Logo

Epic Games

Genus Breeding Ltd Logo

Genus Breeding Ltd

NIT A/S

MacDonald Humfrey (Automation) Ltd. Logo

MacDonald Humfrey (Automation) Ltd.

Kongsberg Maritime Logo

Kongsberg Maritime

Philips Logo

Philips

Higher Education Statistics Agency Logo

Higher Education Statistics Agency

Alignment Healthcare Logo

Alignment Healthcare

Qualco Logo

Qualco

Lean SA Logo

Lean SA

Capita Secure Information Solutions Ltd Logo

Capita Secure Information Solutions Ltd

Sage Logo

Sage

Healthgrades Logo

Healthgrades

Flowmaster (a Mentor Graphics Company) Logo

Flowmaster (a Mentor Graphics Company)

Ericson Logo

Ericson

Brandes Investment Partners L.P. Logo

Brandes Investment Partners L.P.

Cognizant Microsoft Business Group (MBG) Logo

Cognizant Microsoft Business Group (MBG)

Royal Air Force Logo

Royal Air Force

Nottingham County Council Logo

Nottingham County Council

New Hampshire Supreme Court Logo

New Hampshire Supreme Court

Ghana Police Service Logo

Ghana Police Service

Department of Work and Pensions (UK) Logo

Department of Work and Pensions (UK)

Washington Department of Transport Logo

Washington Department of Transport

Epic Games Logo

Epic Games

Deliotte Logo

Deliotte

Alignment Healthcare Logo

Alignment Healthcare

Xceptor - Process and Data Automation Logo

Xceptor - Process and Data Automation

Teleplan Logo

Teleplan

Sage Logo

Sage