CountryComboBox
The CountryComboBox can be used to select a Country from a list of countries in the world. The country code can then be used with LINQ and CountryCurrencyMapping to query the Currency that is used in that Country.
Overview
The CountryComboBox extends the native ComboBox
and displays a list of countries as defined by the ISO. A country is represented by an instance of Country, and the list of countries is defined by the Country.Countries collection
List of Countries
The list of countries can be customized by updating the Country.Countries collection. Items can be added or removed as needed directly from this list. In addition, a custom list can be assigned to the ItemsSource
property.
This example code shows how the default full list of countries can be filtered down to several European countries via LINQ:
var countries = new string[] { "PT", "ES", "GB", "FR", "DE" };
countryComboBox.ItemSource = from c in Country.Countries where countries.Contains(c.Code) select c;
Selection
The selected Country is accessible through the SelectedItem
property. In addition, the unique ISO code associated with the country can be accessed through the SelectedValue
property.
Country/Currency Mapping
The CountryCurrencyMapping class contains Mappings between Country.Countries and Currency.Currencies. This is useful for seeing which countries use which currencies, and which currencies are used by which countries.
It is possible to use LINQ with CountryCurrencyMapping.Mappings, Country.Countries and Currency.Currencies. This shows the currencies for the United States.
var results =
from mapping in CountryCurrencyMapping.Mappings
join currency in Currency.Currencies on mapping.CurrencyCode equals currency.Code
where mapping.CountryCode == "US"
select currency;