I'm customizing an ArcFM Silverlight viewer (which is essentially an ArcGIS Silverlight viewer in a different package and with some additional tools). I managed to make a legend via the Legend Class and Sample: Legend with Templates.

the legend in my viewer

The last three layers (InsetMapMarker, TextTemporary, and BufferLayer) are things automatically generated by the ArcFM viewer tools. It will confuse to end users to see them ("what's a buffer layer, I'm not making any buffers"), and potentially mess with functionality if they turn them on or off. So I really ought to exclude them from the legend.

I was very happy to find this Q&A How do I exclude raster layers from legend? (Silverlight, ArcGIS Server) and adapted the code snippet to exclude the last three layers (see below). However, this has no effect -- they're still visible in the legend.

private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e)
    LayerItemViewModel removeLayerItemVM = null;

    if (e.LayerItem.LayerItems != null)
        foreach (LayerItemViewModel layerItemVM in e.LayerItem.LayerItems)
            if (layerItemVM.IsExpanded)
                layerItemVM.IsExpanded = false;
            if (layerItemVM.Label == "InsetMapMarker")
                removeLayerItemVM = layerItemVM;
            if (layerItemVM.Label == "TextTemporary")
                removeLayerItemVM = layerItemVM;
            if (layerItemVM.Label == "BufferLayer")
                removeLayerItemVM = layerItemVM;

        if (removeLayerItemVM != null)
        e.LayerItem.IsExpanded = false;

I know very little about C# and the Silverlight API, and guessing isn't getting me very far. What am I missing?

1 Answer 1


I eventually found a solution to this in a discussion on Esri's GeoNet: Controlling Layers in Legend Control. The method is to include a LayerIDs="[list]" property in the legend declaration.

So for instance, you only want to display your baselayer in the legend:

<esri:ArcGISTiledMapServiceLayer ID="baseLayer" Url="..." />

in legend:

<esri:legend Map="{Binding ElementName=MyMap}" 
ShowOnlyVisibleLayers="True" />

To add layers to your legend, just separate them by a comma.

This worked in my case, since I have a limited set of layers and they are not going to change frequently (if ever). There are additional suggestions later in that discussion about removing all graphics layer, etc., however I didn't need a solution that advanced and so haven't tested it.

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.