Sharing code between two WP7 projects

Thursday, 10 February 2011

So you want to publish a free (aka 'lite') as well as paid versions of your Windows Phone 7 app? Ideally you can do this with a minimum of duplication between the two projects. This is how I've approached the problem.

Create second project

Assuming you've got a solution with a working WP7 project (I'll refer to this as 'primary'). Add a new WP7 project to your existing solution (referred to as 'secondary'). In the new secondary project, add a reference to the primary project.

Move resources into resource dictionary

If you have any resources defined in your App.xaml file, you should move them to a separate xaml file and use a ResourceDictionary to reference them.
Here's a cutdown version of my Styles.xaml. This lives in the primary project and has a build action of 'Page'.
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns=""
                    xmlns:x="" xmlns:unsupported="clr-namespace:Microsoft.Phone.Controls.Unsupported">
    <Style x:Key="PerformanceProgressBar" TargetType="ProgressBar">
App.xaml for primary
I've been using Caliburn Micro framework so the bootstrapper property has to be moved inside the nested ResourceDictionary.
<Application x:Class="Primary.App"
             xmlns:x="" xmlns:local="clr-namespace:Primary">
        <ResourceDictionary >
                    <local:AppBootstrapper x:Key="bootstrapper" />
                <ResourceDictionary Source="Styles.xaml" />

App.xaml for secondary
In this file, we need to fully specify the path to Styles.xaml
<Application x:Class="Secondary.App"
        <ResourceDictionary >
                    <local:AppBootstrapper x:Key="bootstrapper" />
                <ResourceDictionary Source="/Primary;component/Styles.xaml" />
In my case, the secondary project has it's own AppBootstrapper class that inherits from the primary project's similarly named AppBootstrapper.
There's more info on using ResourceDictionaries with WP7 in this StackOverflow question.

Make page navigation Uris fully qualified

If you have any NavigationService calls to navigate to other pages in the primary project, they will need to be fully qualified so that they continue to work when called from the secondary project.
_navigationService.Navigate( new Uri( "/Primary;component/SettingsPage.xaml", UriKind.RelativeOrAbsolute ) );

Fully qualify the value of the NavigationPage attribute in the WMAppManifest.xml file

Assuming you want the same page to load at the start in the secondary project, you'll need to change the reference in the NavigationPage attribute in the WMAppManifest.xml file.
  <DefaultTask Name="_default" NavigationPage="Primary;component/MainPage.xaml" />
Bear in mind that if you edit the application properties through the Visual Studio project properties interface, this will revert the NavigationPage value back to just "MainPage.xaml", so you'll need to update it again.

Add links to existing files for all 'Content' files and application bar images

imageAny files in your primary project that have a build action of 'Content' will need to be added to the secondary project. Add them as existing items and choose the 'Add as link' option so you just reference the existing file. Update the build action of all of these files to be 'Content'. Common examples of these files would include ApplicationIcon.png and Background.png.
Likewise, if you have any application bar icons, you'll probably need to do the same.


Following these steps produces a nice lean secondary project like this:
It's hard to see from the icons (as Mercurial has overlaid green ticks on top), but the only unique files to the project are App.xaml, AppBootstrapper.cs and the contents of the Properties folder. All the others are linked to ones in the Primary project.

IsolatedStorageSettings extension method

Thursday, 3 February 2011

I noticed that my Windows Phone 7 applications started to have lots of these kinds of statements in the OnLaunch and OnActivate event handlers:

IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
bool allowLocationService;
AllowLocationServiceProperty = settings.TryGetValue( "AllowLocationService", out allowLocationService ) ? allowLocationService : false;

I came up with simple this extension method to reduce the repetition:

/// <summary>
/// Gets a value for the specified key
/// </summary>
/// <typeparam name="T">The System.Type of the value parameter.</typeparam>
/// <param name="settings"></param>
/// <param name="key">The key of the value to get.</param>
/// <param name="default">A value to return if the key is not found.</param>
/// <returns>When this method returns, the value associated with the specified key if the key is found; 
/// otherwise, the value of <paramref name="default"/>. </returns>
public static T TryGetValue<T>(this IsolatedStorageSettings settings, string key, T @default)
    T value;
    return settings.TryGetValue( key, out value ) ? value : @default;

Which means I can now do:

IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

AllowLocationServiceProperty = settings.TryGetValue( "AllowLocationService", false );

That's a bit better!

There's a few other examples in this thread in the Windows Phone 7 forums.

Comparison of public weather forecasts for Adelaide

Wednesday, 2 February 2011

If I want what I consider the most accurate forecast for Adelaide, I'm going to refer to the Bureau of Meteorology forecast. There are a number of other weather sites on the Internet, so let's see how close their forecasts are to what I'll call the "official" one.

Note, temperature is measured in Celsius in Australia, so those are the units I'm displaying. Out of interest, 42°C is equivalent to 107.6°F which is equivalent to hot!

BoM Forecast

Issued at 5:00 am on Monday, 31 January 2011

Monday               Max 42   Dry. Sunny.

Tuesday     Min 24   Max 33   Fine. Mostly sunny.
Wednesday   Min 20   Max 34   Fine. Mostly sunny.
Thursday    Min 22   Max 34   Fine. Mostly sunny.

Predicting 37°C


I went to the UK version of as that seemed to be the easiest way to get the temperatures in Celsius.

Forecast: 40°C


Forecast: 42°C


Forecast: 32°C



Forecast: 33°C

Looking at the screengrab, I can see why they're called weatherbug.


So as you can see, most of these have absolutely no idea.. I can only presume they are throwing darts at a dart board with the numbers they come up with. Accuweather seemed to be the closest to the Bureau's figures.

And as it turned out, Monday did get to 42°C, so the BoM was on the money.

WP7 Apps–the value proposition

Saturday, 29 January 2011

I've noticed something interesting recently with some of the paid apps appearing in the Windows Phone 7 marketplace. For apps that are essentially just a front-end for publicly available free data, I'm wondering why you would want to pay for them?

For example I chose to publish my Internode Usage app for free (just updated to version 1.1). As I don't have to pay to access the data (Internode make it freely available via a web API) I figure unless the app adds significant additional value then why shouldn't my app be free too?

The same principle applies to the second WP7 app that I've been developing – "Aussie Toilets". It is based on data published by the Australian Government, and as they've already published a free iPhone app, the idea that I would try and charge for basically the same thing on a different platform doesn't seem logical (I'm assuming my app is similar, I haven't actually seen the iPhone one).

You see, for every paid app that uses free data there's a threat looming - another app that uses the same data but which is free. So if a paid app is to be commercially viable then it really needs to stand out – add significant value to the original data (eg. visualisations, interpretations), and stand above any free competition.

There is one reason I can think of for some apps being paid which would otherwise be free. It's related to the fact that developers only get 5 free app submissions per year (but no limit to paid apps), so there is an incentive to publish paid apps (especially considering the penalty for failing app certification for a new free app).

So my challenge to the WP7 developer community – innovate and provide real value, and make the best of an impressive platform. Deliver quality apps, whether they are free or paid. But if you expect me to pay for your app, make sure the value it provides is worth at least the value you are charging for it!

Servicing SQL Server vs Visual Studio

Thursday, 27 January 2011

It's interesting to consider the approach that the SQL Server team take to servicing their products and contrast that with the Visual Studio team.

There are currently 3 versions of SQL Server covered under mainstream support (4 if you count extended support for SQL Server 2000 SP4 until 9th April 2013):

and we know that 'Denali' is in the works as the next version.

Current service packs include:

In addition, 'Cumulative Updates' are also released at regular intervals, and most impressively these also cover multiple service packs for the same RTM versions. As the name suggests, these updates contain all of the hotfixes released since the applicable release. For example the latest cumulative updates include:

You can go to to see all the details.

Now contrast this with current mainstream supported versions of Visual Studio:

There's been single service packs for 2005 and 2008. There's also currently a beta for the 2010 service pack. To the best of my knowledge they've never released additional service packs for any of the '.NET era' VS versions.

Additional updates are released but in very much a piecemeal fashion. It's up to you to look trawl through the items posted to the Connect site or on MSDN and do your research by then trying to look up KB articles as the original descriptions aren't always that descriptive.

I guess what I'm saying is it wouldn't it be great for the VS team to take a leaf out of the SQL team's book and provide a greater commitment to servicing their existing products as well as innovating on the next release – provide proper cumulative updates for current VS releases.