Tuesday, 8 May 2012

Developing my first WP7 app

Back in February I learned that Nokia & Microsoft had teamed up to provide free phones to developers that could show that they were developing applications for Windows Phone 7 (WP7), so I decided that this was too good an opportunity to miss and set about creating my first application.

I already had an idea about what I was going to write as had downloaded an application on my existing WP7, a HTC Radar, to help my son with his math but was frustrated by certain shortcomings such as no tombstoning and I believed that I could write my own app that would keep all the good parts of the existing app but sort out the things I saw as wrong.

Getting Started

As I already have Visual Studio installed all I needed was to download the WP7 SDK and I was able to start coding.

I made the assumption that I could unit test my code and added a WP7 class library (normal class libraries not useable)  used NuGet to get XUnit installed and proceeded to write a failing test.  It turns out I was unable to test against classes directly inside the phone application but I wasn’t overly bothered by this as I was trying to write SOLID code so added another WP7 class library and found I was able to write code to satisfy the test and I didn’t need the emulator running to do so.

I also decided to follow the principle of YAGNI and just build what I needed when I needed it rather than looking to use a framework like Caliburn.Micro so that I could get a better grasp on what was needed to build apps for WP7

Windows Phone Camp

I attended the windows phone camp which was run as part of UK Tech days in Bristol at the end of February, the day had various talks about developing for WP7 as well as a “workshop” area where you could code and receive help from experienced WP7 developers.

I attended the first talk which was all about Metro and designing an application that would fit with the metro design concept but after that I spent the rest of the day in the workshop area and I’m glad I did.

Most attendees stayed in the talks which left me with access to the likes of scottisafool, Peter Foot and not forgetting Pete Vickers so that’s 2 WP7 MVP’s and a very experienced WP7 with time on there hands which meant that as I coded during the day if I ran into a problem I could grab one or other of them to help me with my app, and I have to say I believe I made more progress with them around in that single day than I could of in solo development in 2 weeks.

I also got some sage advise from these good fellows which paraphrased was “don’t be afraid to use code behind, you can do everything in XAML but is the extra time and effort worth it to you?”

The one thing that I didn’t get from the day which I was really hoping for was a phone, but I had the details of how to apply to get one (the details are here just scroll to bottom of the links) and had a fair idea of what was needed to qualify for one.

Developing the app

Due to the simplistic nature of my UI I came away from the phone camp with the UI almost 100% complete and as the majority of functionality in the app I was writing was located in the model so I was able to use TDD to create the functionality I needed. 

Where I was disappointed was that in this day and age Microsoft hadn’t created the libraries that you use with WP7 with seams to enable mocking and testing.  It was because of this I ended up creating my own helper class to enable me to mock one specific interaction and necessitating a change in the design of the application to add interfaces to act as seams for testing purposes.

I was also disappointed by the fact that it is not possible to perform constructor injection on any of the XAML pages, there are alternatives (such as ViewModelLocator) but as I was adhering to YAGNI I didn’t want to have to create the locator class and any additional infrastructure so instead I decided to use Ninject and use a Service Locator pattern.  Whilst I don’t normally like service locator it seemed to me to be the simplest way to achieve composable code in the way I was developing the application.

My fake/stub/mock library of choice is NSubstitute but when I tried to add the package via NuGet I got an error message telling me it was not compatible with WP7 app. I couldn’t see any real reason for this, given I was only trying to test logic, and managed to get around this by simply downloading the latest version from github and referencing it directly from my class library without involving NuGet at all.

I’d read Scott Hanselmans post "From Concept to Code in 6 hours" and looked to some of the same tools he had used in his application to help me namely:

  • Silverlight Toolkit – provides controls that, in my humble opinion, should be part of the normal SDK
  • notifypropertyweaver – just implement INotifyPropertyChanged on a class and at at build time this will add the event and all the necessary plumbing code to the properties.
  • Your Last About Dialog – provides all you need to painlessly implement an about dialog

There was one library that Scott Hanselman used that I didn’t want to and that was LittleWatson, not because there was anything inherently wrong with the library, as I didn’t want the user to have to send me an email with all the gory details in it.  I looked around for alternatives and came across the excellent bugsense that not only provides a library to capture the error and transmit it to a web service but the web service to receive the bug report, a database to store the information and a dashboard for me to view any errors!  The price for this? The free price plan gives you up to 500 errors per month and they only hold onto the data for 7 days but it satisfies my requirements at the moment.

Publishing the app

With the coding done and some graphics created for the app I submitted it to the Windows Phone Marketplace through the App Hub, which in itself was a fairly painless process and I made the app free as I believe that WP7 needs more free apps to compete with the other platforms; I have decided to keep the source closed as it was pointed out to me anybody could simply take my code and with little or no change submit it as a paid version.

My only issue with the App Hub was that once submitted I had no idea of timescales for the application to work through the stages to be published, it would be nice to have some of indicator of when the app should reach each stage to set a developers expectations.

The app took just over a day to reach the certification stage but I then had to wait a further 3 days for the certification to be complete and then to be published. 

What is strange is that 3 days after the app has been published I am unable to find the app in the Marketplace if I search for it by name, instead the only way I can find it is via my name as publisher and I’m not sure why its doesn’t appear under a name search.

What now?

I’m hoping some people will download the app and get their children to try the application, after all it is aimed at kids not at adults, I’m more interested in what they have to say about the app. You can view the app details and download it from here.

I already have plans as to how to extend the application but will wait a while and see what feedback I get from the app and see what people actually what before I continue with development.

After publishing I realised that for whatever reason I never finished the description of the application and that I need a better graphic for the market place  so I’m going to have to find out how to amend a Marketplace listing after the app is published to correct these mistakes.

I’m also going to investigate why I can’t find the app when searching specifically for it by name since the app has been published for 3 days now and currently you can only find it by search for me as the publisher, I will update this post if I find the reason.


  1. The information in your post about apps development is more interesting. and this info is more useful for the developers to develop the apps. Thanks for share this valuable information.

  2. Very interesting post.
    With the possibility of a free phone I might take a look at porting my OSx app (once it is complete) to WP7 as well.

  3. I've just got a the HTC Titan and have already thought of an app to create. Have you got a link about the free phone offer? If not I'll come and talk to you at DDDSW assuming you are going? :)

    1. I will be at DDDSW as doing my SOLID talk but you don't have to wait if you go here scroll to the bottom of the links and you'll find the details of what you need to do

  4. Thank you for the NSubstitute tip! I had the same problem myself and really did not want to use another lib ;)