Wednesday, December 19, 2012

MvvmCross + WinRT and default Page templates...

We've got an intern at my working place, which is doing some stuff on WinRT and wants to use some of the MvvmCross code I have written. So I sat down with him today to get him started. 
We got the model code to compile and some of the code, which used Threads instead of Tasks. However our biggest problem was not to get stuff to compile! What was the biggest problem was an issue where at run time, our ViewModel was never set in our Page. So we set up a ton of break points and I think we got through almost all aspects of how MvvmCross locates Views and ViewModels and how it navigates etc., to no avail and had to ask Stuart Lodge on the Jabbr chat for help. 

He gave us a hint about the OnNavigatedTo method in the LayoutAwarePage. The call to base.OnNavigatedTo(e) is what sets up the ViewModel on a page, it was never called! So we starred blindly into the code until we saw that the default template for a Page on WinRT overrides the OnNavigatedTo method itself, and the implementation is empty. So by removing that everything started to work! So be sure to call base.OnNavigatedTo in your Page implementation!

Wednesday, December 12, 2012

Adding View Namespace Abbreviations in MvvmCross

Do you have ridiculously long namespaces for your MvvmCross View bindings? Fear not MvvmCross includes a nice facility to help you easily come over this hurdle of having to type out long namespaces in the AXML view definitions.

So instead of having to define something ridiculous like: You can skip the long namespace by adding an abbreviation and get away with typing: These abbreviations can be added easily with the following lines in your Setup file. Just remember the key is the abbreviation and the value is the namespace you want to abbreviate. Easy, huh?

Horizontal ListView for Mono for Android!

I have previously ported a nice HorizontalPager from Java to Mono for Android, which works fine, however in order for it to work it needs to load all the views into the memory, which can produce a sluggish behavior if using some resource intensive views inside of it. This is where the Horizontal ListView is a lot better as it extends AdapterView instead of ViewGroup, which essentially means it is filled by an Adapter. Why is this good you might ask. This is both good but also very awesome because Adapters help minimizing the memory footprint as they load Views when they are actually needed, contrary to ViewGroup which does not contain such functionality per. default.

The Horizontal ListView was ported from Paul Soucy's implementation for Java and then additional functionality which adds Snap mode and also since I have been working a bit with MvvmCross lately a binding class has been added.

You can check out the project out on GitHub, where there are demo projects included for running on vanilla Mono for Android and one for running with MvvmCross!

I made a short demonstration video, see it here:

Sunday, December 9, 2012

Things to remember before, during and after biking in snow!

So you are determined to jump on your bike and take a ride, even though it is snowing and is windy as hell! Well don't be afraid, as long as you prepare everything should be fine. I just took a long ride in a snow and here is what I gathered from my experience, that might serve you well before and during your bike ride in the snow.

Preparing for the bike ride

Let us start with the bike:
  1. Make sure your tires have tracks and are inflated to specification.
  2. If you have brake-pads on your bike, make sure they have good contact with the rim, as snow will build up at the forks where braking systems usually are mounted.
  3. Internal gears can freeze in the winter, and make sure they are thawed before you go riding in the snow as you will switch gears a lot.
  4. Make sure the bike is oiled up at the moving parts.
Getting you ready:
  1. Dress warm, however not too warm. You are going to work a lot plowing through the snow! Water proof clothing is recommended. Good gloves (i.e. leather) and warm boots or shoes are very recommended.
  2. Be well fed and hydrated before going biking. You can end up being out there for a while if you get stuck. It is not fun to be dehydrated or hungry. Maybe bring something with you if you are going for a long ride.
This should cover the basics, I think we are ready for the actual riding of the bike.

During the bike ride

So now you are ready to roll, I have made some observations, which you might appreciate when you are going out on a ride.
  1. Don't lock your breaks. The surface you are riding on is slippery and locking your breaks will mean the bike will steer sideways, you will have to use your balance and counter steer the front wheel to straighten up the bike again. This can be tricky, but also fun if you are in control.
  2. Watch out riding in car tracks. Cars weigh a lot more than you and your bike and compress the snow, making it difficult to steer through car tracks. Your bike will pull in the direction of the tracks so watch out for tracks steering into driveways and such. The same goes for when you ride in areas where water or snow has become ice, here you should really, really watch out driving in the already made tracks, you can have difficulties getting out of the track again, don't force it just follow it.
  3. Watch out going down hill. Going down hill is fun as you will gain some speed, however watch out at the end of it as you will probably have to break, and here you can easily lock your brakes accidentally.
  4. Get some momentum before going up hill. It will be a lot easier for you to go up hill if you have gained some speed beforehand, especially if the hill is very slippery.

After the bike ride

A good idea is to clean your bike after the bike ride, especially if you care about your bike. So remember to oil the moving parts once in a while. My bike repairman recommends every week during the winter and every 3 weeks during the summer.

Thursday, October 25, 2012

Linking MonoTouch into Reference Assemblies

Jonas Follesø made a nice Visual Studio 2010 extension to allow for loading and compiling MonoTouch projects in Visual Studio. This requires us to copy over some dll files from a Mac computer to the computer running Windows. Once in a while a new version of MonoTouch is released and this process needs to be repeated. Since I am lazy I do not want to do this copy/paste work so I made a small bash script for this which copies the stuff over into a shared folder on my PC called VSMonoTouch. The folder is hard linked to the Reference Assemblies .NETFramework v1.0 folder. So the script looks as follows The script lives in the Windows shared folder, such that when ran it copies it into it. I also link the VSMonoTouch folder the Reference Assemblies like so When a new version of MonoTouch is released I simply run the script :)

Wednesday, October 17, 2012

Reiser4 FS update on SourceForge

I just read a news post on slashdot about Reiser4 FS was updated on SourceForge very recently and it seems that it is still being developed, even though Hans Reiser was convicted for murdering his wife. This news stirred up some very funny comments, which I will posts a couple off them here:

concealment wrote:
If you can find any name that's not related to murdering your wife, go for it. Bonus points if it's catchy.
Anonymous answered:
My vote for MRDRFS.
a reply from tobiasly:
REDRUMFS. As long as you don't use it for mirroring, no one will know.
A comment from serviscope_minor:
There's going to be a few off color jokes. May as well get started.
* It's a killer filesystem.
* My disk died. Was ReiserFS the murderer?
* It's more cutting edge than Reiser's knife.
Jeremiah Cornelius replied:
Kernel merge expected
in 20 years to life.
There are probably more jokes in the comments.

Friday, September 21, 2012

TeamAddins for MonoDevelop

Just recently found out that there is an awesome plug-in for MonoDevelop, which allows for using TFS directly in MonoDevelop. Before I found this plug-in I was using Microsoft Team Explorer Everywhere (TEE), which provided a command line tool, where I could manually check out and check in files, which was quite tedious.

TeamAddins does things similarly to what TFS does in Visual Studio, where it automagically checks out files when editing them and so on.

This plug-in is really awesome if you use TFS in your development environment. To use it simply fire up MonoDevelop, open up the MonoDevelop menu and choose Add-In Manager. Choose the Gallery tab, in the drop down menu choose Manage Repositories. In the new window press Add and  fill out the URL with: Now refresh the repositories and a new item under Version Control called Team Foundatation Server Add-In should appear. Install this and you are ready to set up your workspace and TFS server connections.

Find more information on TeamAddins' web page.

Tuesday, August 28, 2012

MvvmCross: Binding Spinner in Mono for Android

I was playing around with binding a Spinner to a ViewModel using MvvmCross on Mono for Android yesterday, and it was not described anywhere how to do that, but I found a solution in the end.

The relevant parts of my ViewModel look like this:
What I am trying to do is to bind the List of PublicSites to the spinner, and when I select one of these in the spinner it sets the SelectedSite.

The binding itself looks like this:
The two layouts simply contain a TextView each which binds the Text property to the DisplayName property in the NoiseSentinelDirectoryEntryV1 class, which holds the name of the Site, so no magic there. Here there are anyways and they should go into the Resources/Layout folder in your project: There is also a color selector used which is placed in Resources/Color:

Monday, August 27, 2012

Disable Narrator in Windows 8

I am using Synergy on my work setup, where the server runs on a iMac, to that iMac computer an Apple keyboard is connected. On such a keyboard the Windows button and Alt button are switched. So when using my mouse and keyboard on my Windows PC and using Visual Studio with ReSharper, trying to press Alt+Enter for some ReSharper commands, I sometimes accidentally press the Win+Enter combination instead. This opens up the Narrator in Windows 8, which is super annoying! I could not find an official way to disable this, but I found out that changing the permissions for the currently running user helped out a lot.
So here is what I did:

  • Navigate to %systemroot%\System32
  • In this folder a file called Narrator.exe is to be found
  • Right click the file and choose Properties
  • Choose the Security tab and press Advanced
  • In the top of the window press Change to change the Owner permissions
  • In the text field write your username and press OK to all the dialogs
Now you should be able to change the permissions of the file, this is where we remove all the permissions from your user and the user back to system, this way your user will not be able to start the Narrator.
  • Right click the Narrator file again and choose Properties and Security tab
  • Press Advanced
  • Now that you are the owner you can change permissions for other users. Choose your own user and press Edit
  • Remove the Read & Execute and Read permissions and press OK
  • Now press Change in the top under Owner and write system in the text field
  • Press OK to all dialogs
Now you should have removed all your permissions and changed the owner permissions the system, which means you cannot open the program anymore. When pressing the Win+Enter combination nothing should happen now. Enjoy!

Wednesday, August 22, 2012

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!

Tuesday, July 10, 2012

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.

Wednesday, July 4, 2012

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.

Tuesday, July 3, 2012

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");