MvvmCross is Awesome!

I have just had my first breakthrough with MvvmCross, which was made by Stuart Lodge. I have been working a lot with MonoTouch and Mono for Android at my work and during my bachelor thesis and found it annoying that you had to write a lot of controller code to fill out views, update views and so on. On the other hand I was able to use Model-View-ViewModel (short: MVVM) on Windows Phone 7, which more or less eliminates the need for controller code, where you just bind your ViewModel to the View and the ViewModel handles the state of the View and updates the Model as well (for more information read the Article Microsoft wrote on MVVM).

So what MvvmCross does is to bring this pattern to Mono for Android and MonoTouch, which enables a lot more code sharing between the platforms than was possible before. I was working on a large project before where the Model was reusable, but the Views and their Controller code had to be written on both the MonoTouch and Mono for Android platforms. Now with MVVM enabled on the two devices code sharing can be increased a lot more, where not only the model, but also the View states and additionally MvvmCross provides platform specific wrappers for: Opening web pages, playback of sound, creating sharing intents, phone calls, GeoLocation and much much more. Because of these wrappers, the Model and the ViewModel needs only to be written once and can be reused on all three platforms I target. Although there is also support for WinRT and there will be support for Windows Phone 8 when it gets released.

So during the last couple of days I have been studying the Tutorials a lot on how the intended usage of MvvmCross is and have been using that knowledge on a project I am re-factoring to use the MVVM pattern all the way. What I have working now is a "simple" Settings page, which has the ability to save my model to the persistent storage on the devices. But it also gets some of its settings from the world wide web, which complicates things a bit. MvvmCross has the ability through some dependency injection to create services, which are accessible through the ViewModels, which I use for storing my model to the persistent storage, but also for fetching some of my settings from the WWW. The cool thing about this that all my code is contained in the ViewModel and these services and on WP7, Android and iPhone I have some simple Views bound to the ViewModel. No platform specific code at all! That I think is super awesome. All this thanks to the awesome MvvmCross project!

Android Drawable Constant States

I was playing around this evening with the MonoDroid.ActionBar to add some functionality to be able to change themes at run time. For this I had to be able to add new Drawable to be reused for each Action Bar Item. Apparently when you set multiple views BackgroundDrawable with the same Drawable instance, it shares it state between these views. So in my case my Drawable was defined in XML and was a item selector for a button so that a different Drawable can be shown for each of the states: pressed, focused and so on. Then when pressing the items in the Action Bar, triggered the states for some of the other Action Bar Items, so when pressing one button the the state of another button was triggered.

I browsed around the world wide web and found some solutions using the method Mutate() which essentially should remove the shared Constant State in the Drawable, but as it still was the same exact reference I passed along nothing changed. Hence I was forced to duplicate the Drawable:


Above code creates a new Drawble each time I add an Item to the Action Bar and eliminates the problems with the visual state of the Item.

Mono for Android Color Picker sample

I have seen some people asking how to implement a color picker in their Mono for Android application, and it seemed that there were no sample applications showing how to do this. So I decided to create one with different types of Color Pickers.

The Project, which you can find on Github, at the moment contains two different Color Picker dialogs. A simple one, which can also be found in the Android SDK samples and a more advanced one, where hue and alpha can be picked, which was ported from Sergey Margaritov's android-ColorPickerPreference appication.

Simple round color picker from Android SDK samples.

Sergey's Color Picker without the alpha control.

Sergey's Color Picker with the alpha control

The images seem a bit banded, but on the actual device it shows up nice and smooth. This is because the screenshots were taken from the emulator.

Feel free to fork and watch my github repo with the project. Also leave a comment if you want to see other types of color pickers implemented or have questions.

New blog

Dear readers,

I have come to the conclusion that hosting a blog myself is too much hassle. Keeping CMS up to date etc., hence I have started a new blog at instead. This way I can concentrate on posting content instead of managing the CMS.

Hope to see you here soon, where I will post some goodies for you to read.


Console.WriteLine("Live long and prosper");