Magellan and the Microsoft MVVM Toolkit

Back to: Magellan Home

Magellan's MVC framework is designed to handle navigation between views. However, the views themselves, and how they are implemented, is outside of Magellan's concern. Views can be simple XAML pages, or they can be driven by an MVVM or MVP pattern, or any other way you might like.

Microsoft provide a Visual Studio project template known as the MVVM Toolkit, which makes it easy to get started using the MVVM pattern.

To use Magellan with the MVVM toolkit, you can set up a new MVVM project using the MVVM project template. Then configure it the same way as described in the Magellan quickstart.

By default with the MVVM toolkit, you typically create the ViewModel and View and assign them yourself, as shown in the project template:

Views.MainView view = new Views.MainView();
view.DataContext = new ViewModels.MainViewModel();

Instead, with Magellan, you can assign the controller's Model property to you ViewModel:

public class HomeController : Controller
    public ActionResult Main()
        Model = new MainViewModel();
        return Page();

The view engines will create the page or Window, and set the DataContext to the Model for you. It will then navigate to the page or show the Window.

Your ViewModels can make use of commands, event managers, data binding, and all the other common MVVM patterns. MVVM would typically handle:

  • Local interaction with the view
  • Validation
  • Control state, such as whether a button should be enabled based on data

While Magellan would be used for:

  • Navigating to another page or window

A good way to think about this is to think in terms of the web. On the web, JavaScript is typically the "view model" - it handles the logic for a particular page. The server processes requests for many pages and navigation between pages - that's the job of Magellan.

There is also a NavigateCommand that can be used in ViewModels, instead of the need to use a DelegateCommand/RelayCommand for common navigation events.

Back to: Magellan Home

A picture of me

Welcome, my name is Paul Stovell. I live in Brisbane and work on Octopus Deploy, an automated deployment tool.

Prior to founding Octopus Deploy, I worked for an investment bank in London building WPF applications, and before that I worked for Readify, an Australian .NET consulting firm. I also worked on a number of open source projects and was an active user group presenter. I was a Microsoft MVP for WPF from 2006 to 2013.

George Rolfe
George Rolfe
25 Mar 2010

So in order to get input validation, do I have to use one of these viewmodel frameworks? ie. in the sample if you type in letters rather than numerals, it takes a dump and throws an exception. Ideally it just wouldnt accept the input or you could so something fancy via an attribute to set a min and max or something - is that what MS MVVM would be for?