I have published a mapserver on my ArcGIS Server 9.3. I am developing a silverlight application using ArcGIS Silverlight API. Now I can load my map into my application and also the list of my layers that I can toggle their visibility. I just want to load my map legend in order to know the legend of each layer. The solution which I find in arcgis silverlight example is just as follow:

<esri:Legend Map="{Binding ElementName=Map}" 

In visual studio 2010, I have an error for LayerIDs part which says that "Unable to cast from....". The definition of my map is also:

<esri:Map x:Name="Map"  Background="White" MouseClick="QueryPoint_MouseClick" IsLogoVisible="False">
    <esri:OpenStreetMapLayer ID="OpenStreetMap" Style="Mapnik">

    <esri:ArcGISDynamicMapServiceLayer ID="BaseLayer"   
    Initialized="ArcGISDynamicMapServiceLayer_Initialized" />            

It also doesn't show any of my legends for BaseLayer map. Am I missing something or is there any problem with my map?

2 Answers 2


Crazy, but nevertheless... I was using AGS 10 sp1 and could not get a legend to show up from an internal test server (it could not connect to internet). For AGS below 10 sp2, AGS must be able to connect to ESRI servers to generate a legend. Upgrading to sp2 solved the problem because the legends are created on your own server. So crazy and unexpected...

From jsapi (but would apply to all) --

"If the layers are version 10 or lower the legend is created using the ArcGIS.com legend service. In order to use the ArcGIS.com legend service your map service needs to be publicly accessible and your application must be able to access ArcGIS.com."



It looks like you can't bind the Legend layer in XAML. Either bind it in the MainPage (or whatever your .XAML file is) constructor, or the Map loaded event. This works for me:


<esri:Map Name="Map" >
    <esri:OpenStreetMapLayer ID="OpenStreetMap" Style="Mapnik">
    <esri:ArcGISDynamicMapServiceLayer ID="BaseLayer"   
        Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/RecentEarthquakesRendered/MapServer" />
    <esri:Legend  Map="{Binding ElementName=Map}" Name="Legend1" LayerItemsMode="Tree"/>


public MainPage()
        Legend1.LayerIDs = new[] {"BaseLayer"};
        Legend1.ShowOnlyVisibleLayers = false;

enter image description here

  • Thanks for your reply. Actually I used exactly your code and your map server, but again I got nothing. Is there any problem in config or something like that?
    – Sina M
    Jan 26, 2012 at 7:14
  • In order to proceed you'll need to provide some information as to debug, errors, warnings etc. Jan 26, 2012 at 16:43
  • You'll need ArcGIS Server 10 SP2 to generate legends in-house. Otherwise, see awesomo's answer.
    – mwalker
    Feb 29, 2012 at 0:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.