Select to view content in your preferred language

Silverlight Legend control with uniqueValue

553
1
02-08-2011 06:33 AM
AlirezaAhmadi
Emerging Contributor
I like to show the name of the field that has uniqueValues. I can see the name of the field as "defaultLabel" in REST but I do not know how to bind it inside esri:Legend.MapLayerTemplate.

http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer/0?f=json&pretty=true

I tried this :

                                       <StackPanel Orientation="Vertical">
                                            <TextBlock Text="{Binding Layer.defaultLabel}"
                                                       FontWeight="Bold"
                                                       VerticalAlignment="Center" />
                                        </StackPanel>

but it did not work.
0 Kudos
1 Reply
JenniferNery
Esri Regular Contributor
I'm not sure how you could construct a Binding statement directly, you might need to write a converter for this.

Label comes from the UniqueValueRenderer http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.UniqueValu.... Renderer from the GraphicsLayer can be of any Renderer type that implements IRenderer. http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.GraphicsLa...

You can try this code after the layer is Initialized and see that you can retrieve this value.
 
GraphicsLayer MyGraphicsLayer = sender as GraphicsLayer;
if (MyGraphicsLayer.Renderer is UniqueValueRenderer)
{
 UniqueValueRenderer renderer = MyGraphicsLayer.Renderer as UniqueValueRenderer;
 string label = renderer.DefaultLabel;
 foreach (var info in renderer.Infos)
  label = info.Label;
}


You can create a converter that accepts layer and value so that when you can break from the loop when a matching value is found (info.Value == parameterValue).
0 Kudos