O'Reilly logo

Microsoft Silverlight 5 Data and Services Cookbook by Kevin Dockx, Gill Cleeren

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Connecting a View to a ViewModel using a ViewModelLocator

Applies to Silverlight 3, 4, 5 and WP7

One of the first things you'll have to decide on when working with the MVVM design pattern is how you're going to connect your Views to your ViewModels. The simplest method by far is by just instantiating the ViewModel in the View's constructor, but this of course breaks the idea that we're trying to work as loosely coupled as possible (even though a View and ViewModel are somewhat coupled by design, as a ViewModel needs to have the properties used in the View's binding syntax).

The approach used in MVVM Light is that of the ViewModelLocator. In this recipe, we'll learn how to use this ViewModelLocator to tie your View and ViewModel together.

Getting ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required