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!

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:

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.

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 :)