Select to view content in your preferred language

How can I make the Legend tree nodes collapse by default?

2227
3
08-08-2011 12:13 PM
weiliang
Deactivated User
Hi,

I am using ESRI's Legend with template for my TOC, but by default, the most levels of the tree nodes are expended. Is there a easy way that I can collapse these nodes at the initialization phase?

Also in the Legend, in one of our dynamic map service, we want to change the map service URL to another service if the user click a button.  The legend refreshes automatically, however, the on/off check boxes are kind been changed from the initial service settings (e.g., some check boxes, which should be unchecked by default, are checked, and vice versa). Is there a way that I can fix it?

Any help is welcome.

Wei
0 Kudos
3 Replies
weiliang
Deactivated User
Can somebody help me out? Especially for the service URL changing issue.

Many thanks,

Wei
0 Kudos
TerryGiles
Frequent Contributor
The code below is in the legend's Refreshed event and should collapse all nodes under each layer.  Not sure on the check boxes - maybe rebind the the map property of the legend?

        private void mapLegend_Refreshed(object sender, Legend.RefreshedEventArgs e)
        {
            CollapseLayerItems(e.LayerItem);
        }

        private void CollapseLayerItems(LayerItemViewModel livm)
        {
            //collapses a node in the legend tree and all of its sub layers recursively
            livm.IsExpanded = false;
            if (livm.LayerItems != null)
            {
                foreach (LayerItemViewModel sublayerItemVM in livm.LayerItems)
                {
                    CollapseLayerItems(sublayerItemVM);
                }
            }

        }
0 Kudos
weiliang
Deactivated User
Many thanks, Terry. I will try to see if it works for me.

Wei
0 Kudos