Select to view content in your preferred language

Maptip Multiple Field Binding

973
4
05-25-2011 08:55 AM
DanielSanders
Occasional Contributor
I would like to format city, state, and zip (separate out fields) and display them in a maptip. It's possible to create separate text blocks with bindings for each field and then put them in a horizontal stackpanel, but it seems like there should be an easier way. I tried using a converter, but the object passed to the Convert method is of type ESRI.ArcGIS.Client.Graphics.ObservableDictionary and I can't figure out how to cast it correctly to get the values out. What is the best way to do this?

Thanks...
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
The datacontext of the maptip is set to the Attributes property of the current graphic.
Attributes is an ObservableDictionary, so if you bind to the datacontext itself (i.e. {Binding} without path) you get the Observable dictionary.
If you use a converter, this converter will get this dictionary as input, so you can use it to generate the string you want.
By supposing your attributes are called "City" and "State":
 
public object Convert(object value, .....)
{
  ObservableDictionary dict = value as ObservableDictionary;
  return format.String("City = {0}  State =  {1}", dict["City"], dict["State"]);
}
0 Kudos
DanielSanders
Occasional Contributor
Thanks for you reply. This line gives an error:
ObservableDictionary dict = value as ObservableDictionary;

I think I'm missing a reference. Do you know what assembly ObservableDictionary is in?

Thanks
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Sorry my mistake.  Observable Dictionary is not public:confused:

Attributes is declared as  'IDictionary<string, object>'

so the code should be:

 
public object Convert(object value, .....)
{
  var dict = value as IDictionary<string, object>;
  return format.String("City = {0}  State =  {1}", dict["City"].ToString(), dict["State"].ToString());
}


Sorry for the confusion.
0 Kudos
DanielSanders
Occasional Contributor
Awesome. That works. Thanks for your help!
0 Kudos