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 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.LayerItems.Remove(removeLayerItemVM);
}
else
{
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?