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!