Teemu Tapanila bio photo

Teemu Tapanila

CTO of Mallow

Email Twitter LinkedIn Github

I love Model View ViewModel (MVVM) pattern when doing Windows Phone or Windows 8 development. It allows nice separation of UI and code which gives your project very good structure. There’s basically two common MVVM toolkits out which are MVVM Light and Caliburn Micro.

I first used MVVM light heavily but have recently moved over into Caliburn Micro. Biggest difference is that caliburn uses naming convention while mvvm light doesn’t. Using naming conventions makes you fast but it also raises the barrier if someone not familiar with the pattern is looking at your code.

Considering the facts I do recommend using Caliburn Micro and here’s sample how to get started and Build Windows Phone 8 hello world with Caliburn Micro.

  1. Create new Windows Phone 8 basic project
  2. Install Caliburn.Micro.Start nuget package
  3. Create new folder into your project "Views"
  4. Create new folder into your project "ViewModels"
  5. Drag MainPage.xaml and MainPageViewModel.cs to their folders
  6. Change Navigation Page from WMAppManifest.xml to "Views/MainPage.xaml"
  7. Remove everything else than InitializeComponent() from app.xaml.cs
    using System.Windows;
    namespace TT_WP8_Caliburn_1
    {
    public partial class App : Application
    {
    public App()
    {
    InitializeComponent();
    }
    }
    }
    view raw App.xaml.cs hosted with ❤ by GitHub
  8. Edit your app.xaml
    <Application
    x:Class="TT_WP8_Caliburn_1.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ttWp8Caliburn1="clr-namespace:TT_WP8_Caliburn_1">
    <Application.Resources>
    <ttWp8Caliburn1:AppBootstrapper x:Key="Bootstrapper" />
    </Application.Resources>
    </Application>
    view raw App.xaml hosted with ❤ by GitHub
  9. Prepare your first viewmodel
    using System.Windows;
    using Caliburn.Micro;
    namespace TT_WP8_Caliburn_1.ViewModels {
    public class MainPageViewModel : Screen
    {
    public MainPageViewModel()
    {
    MessageBox.Show("Hello world! from MainPageViewModel");
    }
    }
    }
  10. Clean MainPage.xaml.cs
    using Microsoft.Phone.Controls;
    namespace TT_WP8_Caliburn_1.Views
    {
    public partial class MainPage : PhoneApplicationPage
    {
    public MainPage()
    {
    InitializeComponent();
    }
    }
    }
  11. Enjoy your end results

If you have any questions regarding how to use Caliburn Micro with Windows Phone 8 or Windows 8 please do so on comments. Whole solution can be found here.