3

is it possible to get list of country names and country codes somehow from phone? E.g. the list of countries is displayed in Settings.

Or can I easily get country name from country code like gb,de,fr,cs,...

Thank you

luccio
  • 485
  • 1
  • 6
  • 24

4 Answers4

2

Because of absence of some functions in silverlight version of CultureInfo and RegionInfo I decided to use resource file with international code and international country name.

The list of countries is provided here: https://gist.github.com/901679

I really don't know why silverlight version doesn't support same functions like .NET version of Culture/RegionInfo.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
luccio
  • 485
  • 1
  • 6
  • 24
1

If you need a simple list you can store it locally and retrieve it using a number of options (resx, sql db, etc).

However if you want to detect the country based on the region/country code please consider the following option:

using System.Globalization

string countryCode = "en-US"; 
try {
    RegionInfo reg = new RegionInfo(countryCode);
        string name = reg.Name;
        string displayname = reg.DisplayName;
        string ISORegion = reg.TwoLetterISORegionName;
        string currency = reg.CurrencySymbol;
} 
catch (ArgumentException argEx) {
    // The country code was not valid 
}

More Info here: http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo.aspx

Hope this helps!

poppastring
  • 317
  • 1
  • 9
  • this would be great, but it is not working. When I try your example on WP7 it returns "Value does not fall within the expected range." exception. So I tried to get info about CurrentRegion: RegionInfo.CurrentRegion and it has all fields empty except DisplayName which is in my case Czech Republic. – luccio Feb 05 '12 at 09:56
  • Made a slight modification, also noted that "US" is not valid you need to be more specific with the culture. Hope this helps – poppastring Feb 06 '12 at 15:04
1

I dont think you can get the cultures in code, but here is a list of Accepted Cultures

  • USA, English, en-US
  • UK, English, en-GB
  • Germany, German, de-DE
  • France, French, dr-DR
  • Spain, Spanish, es-ES
  • Italy, Italian, it-IT
  • Canada, English, en-CA
  • Canada, French, fr-CA
  • Australia, English, en-Au
  • Mexico, Spanish, es-MX
  • Ireland, English, en-IE
  • New Zealand, English, en-NZ
  • Belgium, French, fr-BE
  • Austria, German, de-AT
  • Switzerland, French, fr-CH
  • Switzerland, German, de-Ch
  • Singapore, English, en-SG
  • Hong Kong, English, en-HK
MyKuLLSKI
  • 5,285
  • 3
  • 20
  • 39
0

In my thought, there is no API to you get all the countries supported from the Settings.

But you can refer the following link to get the all the Culture and language supported for Windows Phone.

Santhu
  • 1,535
  • 8
  • 11