Select to view content in your preferred language

Legend - Hiding layers in the treeview

4918
10
12-09-2010 06:36 AM
AndrewWhite
Emerging Contributor
I would like to hide specific layers in the Legend but still have them show up on the map.  I'm not talking about MapService layers which are easy to hide by not including them in the Legend.LayerIds property. 

Specifically, we've got annotation sublayers that we need on the Map but are just noise on the Legend.

Within the LayerTemplate I've got a StackPanel that I'm Collapsing if it's an annotation sublayer.  However, that just leaves an empty node in the Legend TreeView.  I'm guessing I need to Collapse the TreeViewItem itself, but I can't figure out how to access it.
0 Kudos
10 Replies
DominiqueBroux
Esri Frequent Contributor
Refreshed event is fired once by map layer as soon as the legend infos are available for the layer.

If your map contains a dynamic map service layer and a feature layer, your event handler will be called twice.
By testing the LayerItem given by RefreshedEventArgs, you can know which layer legend you are working on.

To change a label, your code should look like:
private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e)
{
if (e.LayerItem.Layer.ID == "MyFeatureLayer") // could be a test on old label, layer type, url, ...
    e.LayerItem.Label = "MyAlias";
}
0 Kudos