I've recently been working to update my Windows Phone app #places to allow the user to customize a few of their search options. One of those settings is the unit of measurement for the distance between the user and the search result. In a nutshell, I want the user to be able to choose between Miles and Kilometers.

While in development I came across the problem of specifying a default value for the setting. Naturally, I thought to make the default value Miles because that's the value I use. However, since my users span around the world, I figure I should make the default value equal to whatever the current user's regional default is. This turned out to be much easier than I had expected.

This was made very easy by including a using statement for System.Globalization. Then within the System.Globalization namespace there is a property called RegionInfo.CurrentRegion.IsMetric. Simple! This is all I need to determine if the user prefers Kilometers or Miles. I  can perform a basic if statement off of the IsMetric boolean value and return the appropriate DistanceType. If the user does not like the default setting provided by their regional information, I still give them the option to change it to whichever units they prefer.

Here is a snippet of the code I am using:

Things to note are I'm using Ninject to pass in IStorageRepository which is simply an abstraction I have written over the Phone's internal APIs (which I will probably blog about at a later date). You could just write directly to the IsolatedStorageSettings within this class if you prefer.

There are many other settings within System.Globalization.RegionInfo.CurrentRegion and System.Globalization.CultureInfo.CurrentCulture objects that can help you to target your Windows Phone apps to a global audience.