You don’t need an MVVM framework to have a view factory and view model navigation in your Xamarin.Forms app


Quite often I get asked what MVVM framework I use when creating apps, or I’m presented a list of MVVM helpers/frameworks/toolkits and am supposed to pick my preference. Let me admit that I indeed do have a preference (it is the MvvmLight toolkit) but this does not mean that my choice is the right choice for you, your project or your team. In fact, I think that there’s quite some misconception going on: many think that using a framework is a requirement to build an MVVM based app. That’s not true. Let’s see what the definition of MVVM is over at Wikipedia:

MVVM facilitates a separation of development of the graphical user interface – be it via a markup language or GUI code – from development of the business logic or back-end logic (the data model). […] MVVM is a variation of Martin Fowler’s Presentation Model design pattern.

There isn’t a single reference to a specific framework, in fact it is not even limited to a specific platform. It is all about decoupling your UI from the actual logic – that’s it. The frameworks and toolkits out there can help you reduce the amount of code you have to write. Code that would otherwise be repetitive and they also add nice features like handling view model navigation which is the topic I want to cover in this blog post.

My intention is to show you that you can focus on creating your app instead of spending too much time on finding the “right” framework. Also, you might not need most of what these frameworks give you or you don’t agree on the way things work in them, or whatever the reason may be.

Building a MAME Arcade Cabinet

Born in 1976 I still remember the great arcades from my first visit to London at the age of 17. We also had arcade machines in our small town, in almost every restaurant there was a PacMan, Double Dragon or some other machine showing off amazing graphics. I remember discussing with a friend how home computers or consoles would never ever be able to reach such awesome performance. We were young. And wrong.

Meanwhile, arcade machines have become a thing of the past and when I was in the process of building my own, my son’s friends (aged 9) asked me what I was doing there. When I answered that this was an arcade machine, they just said “Ok.” and moved on, probably thinking it was some sort of IKEA storage cabinet for my kitchen. They simply did not know what an arcade machine was!

When I was 21, I had an original arcade machine in my apartment. It was some Double Dragon like game. I bought the full size arcade for DM700 back then (about €360) and sold it two years later for about €150. At the same time, a friend bought a table video game with a version of Space Invaders and he still has it.

Every time I visit him I would get angry at myself for selling my own arcade. Well, no more!

But I don’t need the complete Github repo!

We all love example code and there’s plenty of code hosted on Github. Xamarin for instance has a large repository at https://github.com/xamarin/mobile-samples/. And of course Github makes it very easy to download such a repo by just hitting the big green button:

Button to download a Github repo

Download a repo

But right now I’m on the train, tethered to my iPhone and I just don’t feel like downloading the entire repo, all I want is the CoinTime game app!

Here’s how I solve this problem: instead of using Git, I use Subversion (SVN) which is supported by Github, too. Just open Terminal and run the following command:

svn checkout <URL>

where <URL> will be replaced with the actual project to clone.

In my example, CoinTime’s URL is:


To use SVN, we simply replace “tree/master” with “trunk” and the command becomes:

svn checkout https://github.com/xamarin/mobile-samples/trunk/CoinTime

And we have a subfolder named “CoinTime” with exactly that one project in it!

Using OAuth2 with Microsoft OneDrive and Xamarin.Auth

Last week I had an interesting question about Xamarin.Auth, a library that allows Xamarin apps to authenticate users via standard authentication mechanisms (OAuth2), and store user credentials.

You can see how I wrote the word “standard” in bold because as long as some OAuth2 service follows the standards, Xamarin.Auth should support it. So my answer to whether Xamarin.Auth will work with OneDrive’s OAuth mechanisms was clearly “of course, it does”.

I was wrong.

iOS Background Transfer – what about uploads?

Downloading files in the background is easy with iOS since the introduction of the NSUrlSession background transfer APIs. There are plenty of examples and instructions around for ObjectiveC but also for Xamarin.iOS.

Documentation about the APIs is pretty exhaustive over at Apple and covers everything you have to know to get started.

And then, you start asking yourself: what about uploading data? And it turns out there aren’t so many working examples and in fact it can be quite tricky to get things up and running. I was in contact with Apple support and they helped me to find answers to many of my questions. This blog post is trying to conserve to essence of my mail communication as it can help others who are challenged with implementing background upload.

Launching an Android Activity of another APK

We have discussed Android and its Activity system today. It is quite hard to grasp for an iOS guy like me; it feels…special.

I certainly know how to start an activity within my own app and I understand the difference of an explicit Intent vs an implicit one. But there are a couple of questions I couldn’t find answers to, particularly not something that would show how things work with Xamarin.Android.

So I created a small test app to answer the following questions:

  1. How can another app be launched directly?
  2. How can an Activity of another APK be started via an explicit Intent?
  3. How to implicitly start an Activity of another APK?

Xamarin.iOS, the garbage collector and me

A lot has been written about the Garbage Collector and Xamarin.iOS. Lately, I’ve been hit by some surprises and I want to share my findings. Let me say that there is not a single bug involved! All the issues I describe are either documented or show standard behavior of the .NET runtime. The fact that Xamarin.iOS lives on top of a reference counted world makes things a bit more difficult.

Many thanks to Rolf Bjarne Kvinge for his patience, Marek Safar for sharing the secrets of Mono compiler with me, Rodrigo Moya for helping me with the Xamarin Profiler, James Clancey for his drawings about native reference cycles 🙂 and Chris van Wyk for supporting me in these moments of “good god, this cannot be!”

Adding async/await to CocosSharp actions

UPDATE: The CocosSharp team has decided to integrate my ideas directly into their source! 🙂

Are you a C# programmer? Using Xamarin? Are you interested in making great games that run…

  • cross platform,
  • from one code base
  • and are powered by Cocos2D and XNA?

If yes, then you should check out CocosSharp!

I used Cocos2D in the past (the “good” old days of ObjectiveC…) and liked it a lot. Seeing all this translated to C# just freaks me out! 🙂

However there has been one thing that bugged me: chaining actions and running actions simultaneously.

Say, you want your character to scale, then increase some score counter, afterwards make the character jump and then reset the animation phase to the default frame. You would use something like:

var scale = new CCScaleBy (1f, 1.5f);
var jump = new CCJumpBy (1f, new CCPoint (100, 100), 50, 2);

this.RunActions (scale, new CCCallFunc (() =&gt; this.UpdateScore ()), jump, new CCCallFunc(() =&gt; this.SpriteFrame = this.defaultFrame));[/code]

Works, but with the power of C# we can do better!

Fix too small iOS Simulator on Retina Macs

Recently I received my MacBook Pro. It’s the 13″ model with Retina Display. I run it in the 1680×1050 HiDPI mode to get more content on the screen (I use the nice little tool called QuickRes to conveniently switch resolutions).

Before I had the MacBook Pro I was working on a MacBook Air with significantly lower resolution and when testing my iOS apps in the Simulator, I had to scale the Simulator down to fit on my screen. This can easily be done by pressing CMD+1 (100%), CMD+2 (75%) and CMD+3 (50%) or via the Window -> Scale options.

Now with the MacBook Pro it is the other way round: an iPhone 5 is simply too small even at 100%. See the screenshot below.

Migrating from Parallels Desktop 10 to VMware Fusion 7: Android SDK broken, WP Emulator not working

Recently I switched my Parallels Desktop 10 VM setup to VMware’s Fusion 7. I had various (random) problems with Parallels Desktop 10 and decided to give Fusion a try. The result: Fusion 7 does not support all the fancy DirectX 10 support, but for a virtual Windows 8.1 development machine on my Mac, it is the better choice.

Migrating over was easy: I simply imported the PD10 virtual hard disk. In 30 minutes it was converted over into Fusion’s format and started up just fine. Everything worked pretty well but then I found a view things I had to adjust.