Caliburn.Micro Xaml made easy

Xamarin & Caliburn.Micro

With the cross section of the following technologies increasing amounts of code are being shared across multiple platforms.

  • Portable Class Libraries
  • Shared / Universal Apps & Projects
  • Xamarin (Native)
  • Xamarin.Forms

The idea that we can write our model (thinking in MVVM terms) once and share it across a wide array of platforms. There’s also some appeal to be able to share your view models in the same way.

With Caliburn.Micro we could do this already for the Microsoft XAML platforms. Your view models could be declared in a PCL that references Caliburn.Micro.Core and add something similar to the following code in your app.

ViewModelLocator.AddNamespaceMapping("Example.App.Views", "Example.App.Portable.ViewModels");

The use of Xamarin raises a lot questions.

  • Can we share our view models on Xamarin platforms?
  • What would Caliburn.Micro on Xamarin.Android and Xamarin.iOS even look like?
  • How does Xamarin.Forms fit in to this?

Well the good news is that we’ve started work on bringing Caliburn.Micro to Xamarin and this post is to discuss a potential roadmap and pose some questions to you the community.

Below is a really simple breakdown of the feature-set of Caliburn.Micro and how it’s split between the Portable and Platform Assemblies.

Caliburn.Micro Overview

If we’ve built things right then everything that’s in the Portable assembly will already be ready for use in Xamarin apps. The only part that would be required in the Platform assembly is the piece highlighted below, the Platform Provider. This allows the Portable assembly to do things such as ensuring property changed notifications happen on the UI thread.

Caliburn.Micro Xamarin Initial

I’m really happy to say we have this mostly completed and available on the xamarin branch in GitHub. You can now share your view models across all the XAML platforms as well as Android and iOS!

You can see the start of some of these demonstrations at nigel-sampson/xamarin-experiements.

So where to from here? Part of the discussion I want to foster is which the grey boxes above make sense outside of a XAML framework and in what way do they make sense in these other platforms?

Could we add similar but not exactly the same features on these platforms such as ActivityLocator instead or ViewLocator?

Some of these features make a lot more sense when we consider Xamarin.Forms which is a XAML-like platform. We’d like to keep that as a separate assembly to ensure we don’t end up requiring certain editions of Xamarin. It would also need to be development in a way that Xamarin native development worked hand in hand with Xamarin.Forms.

We’re certainly not promising and exact version of Caliburn.Micro on Xamarin but the most we can speed up your development using similar patterns across multiple platforms the better we’ll all be.

The future is bright!