Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 841245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:45:38+00:00 2026-05-15T05:45:38+00:00

I have a list of data where I keep e.g. countries with code, name

  • 0

I have a list of data where I keep e.g. countries with code, name and some other data.

List<Country> countries = <deserialized objects from file>

which consist of objects like this:

  public class Country
  {
       public string Code { get; set;}
       public string Name { get; set;}
  }

The object which use as a DataContext may look like this:

public class Address
{
    public string StreetName{ get; set;}
    public string CountryCode { get; set;}
}

Then in my XAML I want to do something like this to show the name of the country

<TextBlock Text="{Binding Path=CountryCode, Converter={StaticResource CountryNameLookupConverter}}"/>

But how can I make the CountryNameLookupConverter use the countries list I read from the xml file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:45:39+00:00Added an answer on May 15, 2026 at 5:45 am

    Depending on where you’re exposing the countries collection there are a few different options.

    If countries exists in Address or some other ViewModel object you change your converter to implement IMultiValueConverter instead of IValueConverter and then use a MultiBinding to pass both CountryCode and countries (exposed as a property). You would then access and cast values[0] and values[1] to use them to do the lookup in the Convert method.

    <TextBlock>
        <TextBlock.Text>
            <MultiBinding Converter="{StaticResource CountryNameLookupConverter}">
                <Binding Path="CountryCode" />
                <Binding Path="Countries" />
            </MultiBinding>
        </TextBlock.Text>
    </TextBlock>
    

    If you are exposing countries statically (i.e. Lookup.Countries), you can pass the collection to your IValueConverter either as a property or through the ConverterParameter. Here’s the converter with a property:

    public class CountryNameLookupConverter : IValueConverter
    {
        public IEnumerable<Country> LookupList { get; set; }
    
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Country country = LookupList.FirstOrDefault(c => c.Code.Equals(value));
            if (country == null)
                return "Not Found";
            return country.Name;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Binding.DoNothing;
        }
    }
    

    and the converter resource would be declared like:

    <local:CountryNameLookupConverter x:Key="CountryNameLookupConverter" LookupList="{x:Static local:Lookup.Countries}"/>
    

    Or to pass into Convert’s object parameter instead:

    <TextBlock Text="{Binding Path=CountryCode, Converter={StaticResource CountryNameLookupConverter}, ConverterParameter={x:Static local:Lookup.Countries}}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 443k
  • Answers 443k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Helper classes that are not part of the hierarchy of… May 15, 2026 at 6:20 pm
  • Editorial Team
    Editorial Team added an answer I'm pretty certain you have to specify the using before… May 15, 2026 at 6:20 pm
  • Editorial Team
    Editorial Team added an answer The previous answer is incorrect, if you want to see… May 15, 2026 at 6:20 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.