Windows Store App with Caliburn.Micro - Getting Started

posted on 14 Dec 2012 | Windows 8 App

So I've been learning Windows 8 development recently, specifically with C#/XAML, and Caliburn.Micro for the MVVM goodness. This is all brand new stuff for me, never done any WPF, Silverlight or Windows Phone dev. So I figured it's a good chance to blog what I'm learning.

In this post I want to show you how to get up and running.

I started by reading the blog posts over at Mindscape.

(great series by @Jason, list of links at bottom of this post)

The downside is they were very WPF centric, and a few things getting started have changed. There's no bootstrapper for example.

So, here's my blog series.

Before getting started

The most important thing to note about building Windows Store App's is that you can't just reference any old assembly, it has to be either developed for Windows Store, or be created as a portable library. This is because WinRT (Windows Runtime) doesn't contain all the same namespaces as the .NET framework.

Getting Started

Create a new Blank App (XAML)

Next you're going to need to install Caliburn.Micro, I use Nuget for this, but you can download the package and reference it manually from codeplex.

Your solution should look something like this:

The first thing we can do is delete the MainPage.xaml, and add a couple of folder, Views and ViewModels. You can also add your own Styles file too. While you're at it, add a MainView.xaml and MainViewModel.cs to their respected folders.

Let's start writing/fixing code!


This file is the entry point to your application. It's the very first file that is executed, it's best to leave the file name as is, but if you wish to change it. Then you need to open your Package.appxmanifest file and modify the entry point.

For now, don't worry about changing this, I'll try cover this in future posts.

First thing we want to do is open up the XAML file, not the code file. We can strip back the comments and include our custom styles resource.

Next we want to add in a namespace attribute:


This is like adding custom controls to a web.config file or declaring the custom controls in your page, then accessing them via the prefix you define.

This allows us to modify the root Element and make it a Caliburn Application.

What you should end up with is the following:

                <ResourceDictionary Source="Common/StandardStyles.xaml"/>
                <ResourceDictionary Source="Common/CustomStyles.xaml"/>

The next thing you want to do is open up the code file for the App.xaml file. By default this has a LOT of stuff in it, that we don't need at all.

Below is the recommendation sample from Caliburn.Micro documentation, it does quite a bit including having a basic IoC container for WinRT, and handles View or ViewModel first approach.

Note: Caliburn.Micro 1.4.1 has a breaking change, please read the updated post for info on updating the code below to be compatiable with v1.4.1

using System;
using System.Collections.Generic;
using Caliburn.Micro;
using SampleProject.Views;
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml.Controls;
namespace SampleProject
    sealed partial class App
        private WinRTContainer container;

        public App()

        protected override void Configure()
            container = new WinRTContainer();

        protected override object GetInstance(Type service, string key)
            return container.GetInstance(service, key);

        protected override IEnumerable<object> GetAllInstances(Type service)
            return container.GetAllInstances(service);

        protected override void BuildUp(object instance)

        protected override void PrepareViewFirst(Frame rootFrame)

        protected override void OnLaunched(LaunchActivatedEventArgs args)

The very last method 'OnLaunched' has the class to our Main View, this tells the application that the first thing we will see will be the MainView.

Next lets look at the ViewModel.


In this file, strip everything back and inherit 'Screen'

Although this file will be loaded, it's not going to do anything just yet. At least not for this sample.


Now lets look at the view, open up the xaml file. This file should have been created with as a Blank page, once open, add a TextBlock with the text Hello World.

<Page x:Class="SampleProject.Views.MainView"
    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <TextBlock Text="Hello World" />

We don't need to modify the code file for this.

Now we should be able to run app. There is 3 possible ways to run:

  1. Local Machine

    Using a Local Machine means the application will be loaded into your Start Screen and automatically be run.

  2. Simulator

    The simulator will open up a simulation app which resembles a tablet, this gives a bunch of options to simulate different gestures such as using touch and pinch etc.

  3. Remote Machine

    The remote machine option requires the Remote SDK to be installed and running on a remote machine. This is handy for testing on an actual device. I'll cover this next week when I explain how to setup remote debugging.

I suggest selecting Simulator and pressing F5. Assuming you've followed along you should get this:

Note: I increased the font size for the purpose of taking a screen grab :)

And that's it, so far all we've done is configure Caliburn and tell it to load a view, we aren't really utilizing it yet but we will in the future!

As mentioned here's Jason's post over at Mindscape:

comments powered by Disqus