MVVM / MVC is dead? Is Unidirectional a MVVM / MVC Killer?

Ah so now when you’ve learnt MVC/MVVM, everyone’s decided that we shouldn’t do it anymore? Huh?

MVVM is a great pattern which allows for a clean separation between views and logic, it also lends itself well to unit testing, but is it the only way? If you didn’t already know there’s some new kids on the block, Unidirectional User Interface Architectures which is basically applying the CRQS/Event Sourcing pattern on the client side. The idea of these patterns is to have a single DataStore which is the source of truth and data is updated via events, all Views read from the single source of Data and can only update via events/actions. From what I can gather at the moment, the specific problems they solve are 1) Avoid data being duplicated across viewmodels and stale data 2) Avoid the situation of Fat ViewModels. At the moment this concept is being driven from the web clientside world, but eventually it might make it’s way into the Xamarin world and become popular, maybe? 

There’s new unidirectional frameworks appearing all the time, the ones I’ve looked into recently are Flux and Redux.

Flux Diagram 


Redux Diagram

Redux Diagram

So can we have these in Xamarin? Yes, these are simply design patterns and can easily be implemented in C#. Infact someone has already created a project based on Redux named In some R&D we’ve been doing on a project we’ve also implemented a Xamarin.Forms sample for the project.

Here’s some code from the redux project:

Let’s start with our Application state.

The Actions are basically any changes in your apps state.

The application reducer will then take an Action and modify the state.

Then the UI will be updated, below we see  a UI element binding directly to the state and updating on changes.

Should I use this over Mvvm? Will this kill Mvvm? 

In all truthfulness I (like most people) don’t know if Unidirectional User Interface Architectures are the answer but I feel like they’re going to be around for a while.

I feel like I’ve hardly done these architectures justice in my explanations but I encourage you to look further into these patterns (maybe even try them or built a Unidirectional Framework for Xamarin). Anyways here’s some links for further reading.


Dont forget to subscribe to

FreshMvvm n=3: Navigation in FreshMvvm

Here’s the next video in the  FreshMvvm n+1 series. The idea of this series is to get the video’s out to the eager listeners (you) as quickly as possible, therefore these videos are done live with almost no editing.

Episode Title: n=3: Navigation in FreshMvvm

In this episode we discuss:

  • Review FreshMvvm’s built in Navigation Abilities
  • Understand how navigation works in FreshMvvm

I hope you enjoy.

FreshMvvm n=2 – IOC and Constructor Injection

Here’s the next video in the  FreshMvvm n+1 series. The idea of this series is to get the video’s out to the eager listeners (you) as quickly as possible, therefore these videos are done live with almost no editing.

Episode Title: n=2 – IOC and Constructor Injection

In this episode we discuss:

  • Review FreshMvvm’s built in IOC container
  • Setup a decoupled Data Service with interface
  • Use the PageModel Constructor Injection
  • Use a 3rd Party Library in the IOC Container

I hope you enjoy.



FreshMvvm n=1 : Your first FreshMvvm Application

Here’s the next video in the  FreshMvvm n+1 series. The idea of this series is to get the video’s out to the eager listeners (you) as quickly as possible, therefore these videos are done live with almost no editing.

Episode Title: n=1 Your first FreshMvvm Application

In this episode we discuss:

  • Creating a New Project adding FreshMvvm
  • Automatic wiring of BindingContext
  • PageModel to PageModel Navigation
  • Automatic wiring of Page events (eg. appearing)
  • Basic methods (with values) on PageModel (init, reverseinit)

I hope you enjoy.


Also, if you want to know more awesome things about Xamarin.Forms then my eCourse is a must do! ‘Secrets of a Xamarin.Forms Ninja




Mixing MvvmCross Native Views and Xamarin.Forms Pages

If you’ve read my blog before you probably already know that I’m a avid Mvvm supporter. You’ll also know that I use FreshMvvm alot in my Xamarin.Forms solutions. While I love FreshMvvm it’s always important to pick the right tool for the job.

In a recent project at XAM Consulting we had a project to enhance a large pre-existing application that was built in MvvmCross and ‘Xamarin Traditional’. There was a few things to consider on this project a) it was a pre-existing app with a large amount of business logic b) there was a large amount of changes required c) there was also a large amount of existing Native Views.

If you’ve been in software long enough you know rewriting is the wrong thing to do in the majority of cases. The original application had nice clean code and good architecture, we wanted to keep this but when building new screens it’s very hard to look past the advantages of Xamarin.Forms.

So essentially we wanted to both keep the Native Views and add in a few pages of Xamarin.Forms. Currently all the solutions for MvvmCross and Xamarin.Forms are related to having a Forms app with MvvmCross backend, not mixing the two.

I’ve included a diagram below to help you understand what’s happening in the app.


So what’s the secret sauce? 

It’s important to understand this is really a MvvmCross application but with support Xamarin.Forms pages instead of Native View.

Here’s some of the major components done to implement this, not a step by step guide.

1) Implementing custom MvvmCross presenters

This need to be done in both the iOS project and the Android project. In iOS the class we need to inherit is MvxTouchViewPresenter and we need to override the Show method. In Android the class we need to inherit is MvxAndroidViewPresenter. 

In Android

In iOS

2) Setup MvvmCross to use the new presenters

To do this we need to override the CreatePresenter method on the Setup.

In Android

In iOS 

3) The Secret Sauce

Generally the concepts are the same on both platforms, when we come across a ViewModel ending with XFViewModel then we assume it’s Xamarin.Forms View Model. When it’s Xamarin.Forms ViewModel we 1) Find the Xamarin.Forms Views 2) Convert it into a Native View 3) Setup the BindingContext 4) Display/Native the Native view as if it’s a MvvmCross view.

In iOS 

iOS is was much easier, primarily because Xamarin.Forms allows you to easily create a ViewController.

In Android

It turns out this is a bit harder in Android. This is because Xamarin.Forms Navigation and MvvmCross navigation is very different, Xamarin.Forms has a single Activity for a application while MvvmCross has an activity per page, we need to trick the Xamarin.Forms pages into using a single activity.


Below is the Xamarin.Forms container activity, normally there would only be a single Activity but in this case we want to create a Activity for every page. You’ll also notice we resolve the MvcAndroidLifetimeMonitor and we pass the Forms activity events, this hooks the Xamarin.Forms page into the MvvmCross Navigation.


Now that we have the container for the Xamarin.Forms Page we can override the show method and handle the Xamarin.Forms ViewModel requests.


Android also requires some extra work when Pages/Views are closed, this is because MvvmCross ignores close events if it’s not a MvvmCross view, which in this case it isn’t. So we need to handle the close ourselves and skip the ignore clauses.

4) The helper methods

You might have noticed both the iOS project and the Android project referenced some helper function, here’s the code from the helper classes. The functions are used to help create the View Models and Pages.

The End

So that’s the core pieces of the puzzles, this blog is not a step by step guide so if you want a easy way to see this code work I recommend looking at it on github.

Github Sample Repository

Need an App built or Xamarin.Forms training? – You can hire me!

Want to be a Awesome Xamarin.Forms developer? I’m building a eCourse that’ll teach you all that you everything you need to know.


Creating a Native View from a Xamarin.Forms View

WARNING: this is a expert level technique and isn’t officially supported by Xamarin.

Personally I feel like this is the holy grail of Xamarin.Forms development, having the ability to jump between both Xamarin.Forms Views and Native Views. I’ve used this technique multiple times in Xamarin.Forms apps.

It’s primarily used when you’ve created a custom renderer and you’re working against Native UI APIs, this could be in the native maps API or a 3rd party native component. Now once you’re in the Native area of the application there’s cases where you need to show a view for the user but you still want to have the View shared between the platforms.

To give you an idea the structure might be as follows.

Xamarin.Forms -> Native View

In the diagram above the secret sauce is in orange, taking a Xamarin.Form View and converting that into a native view. This converts to a UIView in iOS and ViewGroup in Android.

Below I’ve written two helper classes that take a Xamarin.Forms view and convert it into the NativeViews. In my experience this code works the best when the Xamarin.Forms view is a Layout.

iOS Converter Class

Android converter class

I’ve created a github sample application, please find it *** Please note this iOS project uses UIPopover which is only available on iPad so you must use the iPad for this demo.

If you want to know more awesome Xamarin.Forms techniques then my eCourse is a must do! ‘Secrets of a Xamarin.Forms Ninja




New Xamarin.Forms eCourse

I’ve been blessed in my career, having the opportunity to join the Xamarin world over 4 years ago. In my 4 years of Xamarin I’ve been able to publish over 8 Xamarin Applications into the App Stores and work on million dollar Xamarin projects. I’ve been a Xamarin.Forms fan since its first release and released many Xamarin.Forms applications into production. I know that there’s been many developers that haven’t had the same success with Xamarin.Forms. In some cases this could be an issue with Xamarin.Forms or an incorrect application of Xamarin.Forms but the truth is ‘anything that can be done in a Native application can be done in a Xamarin.Forms application’ and faster.

After seeing the potential of Xamarin.Forms and diving in head first I now have an amazing amount of knowledge about developing real world applications with Xamarin.Forms. Considering this I’ve decided to share this knowledge with the world.

Without further ado I’m now announcing my first ever eCourse – ‘The Secrets of a Xamarin.Forms Ninja’.

If you haven’t picked it up the Ninja part is inspired from a book named ‘Secrets of the Javascript Ninja’. I felt this naming was very appropriate as the book and my course have the same goal… to teach the secrets that can only be learnt from years developing production applications.

At the moment this course is in a planning stage, so if you would like to be notified on it’s release please sign up below.


Subscribe to for eCourse release info





Links and Code from 10 Awesome Xamarin.Forms Tips and Tricks

This blog post contains the links from my Xamarin talk on Xamarin.Forms tips and tricks. The original slides can be found here. Many of these tips and tricks require full blog posts and I’ll be writing them over the next few weeks. For now it’s just the links to the code.

Here are the links

3rd Party FastCell Solution

This is a 3rd party FastCell implementation, I used it before and found it to work quite well.

TaskCompletionSource Blog Post 

Bindable Property Template

Add some Xamarin.Forms to your MvvmCross app

Converting a Xamarin.Forms view into a Native View

AsyncHelper RunSync

These are just the links so keep an eye on the blog for more blogs and maybe even some training videos.

If you need any help using Xamarin or want to develop a mobile apps please feel free to contact me anytime.