Caliburn Micro 1.1 - Strongly typed navigation for Windows Phone 7

02 June 2011

If you are an MVVM and Windows Phone fan like me, you’ll be very pleased at the announcement that Caliburn Micro 1.1 is available right now.

I wanted to comment on the strongly typed navigation feature in particular.

One common MVVM pattern for dealing with the view first nature of Windows Phone is to constructor inject the INavigationService implementation. This would have been done in your bootstrapper class to wire up Caliburn Micro.

The GoToFoo() method below is fired when some view element has a binding to this method (e.g. a button with x:Name=”GoToFoo”) and we want to navigate to a new page.

The nice thing is we can now do this in a strongly typed fashion including the setting of parameters as required. This is nice because it’s aware only of view models and so you can free to change your view’s name without affecting your VMs.

private INavigationService _navigationService;

public MainViewModel(INavigationService navigationService)
{
    _vmWorker = viewModelWorker;
}

public void GoToFoo()
{
    navigationService.UriFor<FooViewModel>().WithParam(f => f.PageIndex, 3).Navigate();
}      
Want to get started?

We would love to help with your next app or game, please do get in touch.