Select to view content in your preferred language

Converter Question

1313
4
10-08-2010 03:29 PM
AaronEdwards
Emerging Contributor
I'm trying to add a map tip to a feature layer.  The service that the layer is bound to returns a collection of sites, and one of the properties that the service brings back is the primary key, called Site_ID.  In the map tip, I want to display the name of the site, but the service doesn't return it, just Site_ID.

I don't really have access to the service, so I can't just modify it to return the site name.

My page contains a dictionary of side IDs/site names, so I'd like to write a converter at the page level that takes the Site_ID of the site as a parameter, and returns the site name.

I wrote this converter on the page...
    public class SiteNameConverter : IValueConverter
    {
        // assume this dictionary is populated with site_id's, site_names.
        private Dictionary<String, String> siteDictionary = new Dictionary<string, string>();

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return siteDictionary[value.ToString()];
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException("This method will not be called for one-way binding");
        }

    }



Now I just need to figure out how to pass it the Site_ID, to get back the site name. 

Any ideas?

Thanks!
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
You converter is using the main value as SiteID. So, you should get the site name if the source of your binding is the siteID.
Assuming that you declare MySiteNameConverter in the resources et that the property SiteID is giving the siteID, it should be something like:
 
{Binding Path=SiteID, Converter={StaticResource MySiteNameConverter}}
0 Kudos
AaronEdwards
Emerging Contributor
Hey, thanks.

It doesn't actually work because the data context brought back from the map tip is an ESRI.ArcGIS.Client.Graphics.ObservableDictionary.  So Site_ID isn't a member.  We'd need to do something like...

<TextBlock Grid.Column="2" Grid.Row="1" Text="{Binding Converter={StaticResource siteNameConverter}, ConverterParameter={Binding [Site_ID]}}" />


But of course you can't really do that: a binding within a binding.

It's frustrating, because the element above that is a simple textblock displaying the site ID as follows:

<TextBlock Grid.Column="2" Grid.Row="0" Text="{Binding [Site_ID]}"  />


If I could just take that Site_ID somehow and feed it into the textblock above, then we'd have something.

Aaron
0 Kudos
DominiqueBroux
Esri Frequent Contributor
If the SiteID is coming from a dictionary, the code should be:
 
{Binding Path=[Site_ID], Converter={StaticResource MySiteNameConverter}}
0 Kudos
AaronEdwards
Emerging Contributor
That did it.  Thank you so much!

Aaron
0 Kudos