Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Depending on where you're exposing the countries collection there are a few different options.</p> <p>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.</p> <pre><code>&lt;TextBlock&gt; &lt;TextBlock.Text&gt; &lt;MultiBinding Converter="{StaticResource CountryNameLookupConverter}"&gt; &lt;Binding Path="CountryCode" /&gt; &lt;Binding Path="Countries" /&gt; &lt;/MultiBinding&gt; &lt;/TextBlock.Text&gt; &lt;/TextBlock&gt; </code></pre> <p>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:</p> <pre><code>public class CountryNameLookupConverter : IValueConverter { public IEnumerable&lt;Country&gt; LookupList { get; set; } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { Country country = LookupList.FirstOrDefault(c =&gt; 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; } } </code></pre> <p>and the converter resource would be declared like:</p> <pre><code>&lt;local:CountryNameLookupConverter x:Key="CountryNameLookupConverter" LookupList="{x:Static local:Lookup.Countries}"/&gt; </code></pre> <p>Or to pass into Convert's object parameter instead:</p> <pre><code>&lt;TextBlock Text="{Binding Path=CountryCode, Converter={StaticResource CountryNameLookupConverter}, ConverterParameter={x:Static local:Lookup.Countries}}" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload