Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to adjust my Print Widget so that raster layers do not show up in the legend. My thinking was that I could test for a layer type and not add the item to the legend if it is a raster.

Something like:

Foreach (layer in List<Layers>)
    If layer is a raster:
        do nothing;
        Add it to the legend;

I know there's a LayerInfo thing out there but I'm not really sure how to use it. Incidentally, I'm new to C#/Silverlight/ArcGIS for Server so this simple task is a bit challenging for me. I did notice there was a GetType() method(?) that I might be able to use but I'm not sure if how if that is indeed the answer. The foreach legend item code already exists and such -- I'm looking to wrap some conditions around the legendItems.Add bit. I found the following resources, but not sure how to use them if they are helpful... --> the "Type" property, perhaps?

Alternatively, if I'm going about this in a difficult/wrong way, feel free to point that out! I'm a new intern with no prior C#/ArcGIS Server/Silverlight experience so it's all a bit overwhelming.

Thanks in advance!

Thread on arcgis forums:

additional thoughts: -- I'll somehow have to create a list of all the layers, too >_<.

share|improve this question

The code below is taken from the Legend With Templates sample under the Toolkit Controls section. Notice how the legend item named "states" gets removed. You could do the same thing for your raster layer, but instead of checking its label, check to see if layerItemVM.Layer is ArcGISImageServiceLayer See documentation on the is operator for more explanation.

using System.Windows.Controls;
using ESRI.ArcGIS.Client.Toolkit;
using ESRI.ArcGIS.Client.Toolkit.Primitives;

namespace ArcGISSilverlightSDK
    public partial class LegendWithTemplates : UserControl
        public LegendWithTemplates()

        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 == "states")
                        removeLayerItemVM = layerItemVM;

                if (removeLayerItemVM != null)
                e.LayerItem.IsExpanded = false;
share|improve this answer
I could kiss you for pointing me in this direction! It's a brilliant idea. This has contributed to my understanding of how all this ArcGIS Server stuff works (mostly the image service aspect). Thank you! You mentioned testing the layerItemVM.Layer -- I'm not sure how to get the ".Layer" thing working or what's even really meant by that. If you don't mind me troubling you further, could you shed some light on this? – Jenn May 6 '13 at 17:40
Hmm, it doesn't seem like "if maplayer.Layers is ArcGISImageServiceLayer" is a valid test. "The given expression is never of the provided ('ESRI.ArcGIS.Client.ArcGISImageServiceLayer') type". And .Layers doesn't have a "definition or extension method" in the ArcGISImageServiceLayer. – Jenn May 6 '13 at 21:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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