Select to view content in your preferred language

2.1 RC ArcGISDynamicMapServiceLayer.VisibleLayers null with Legend sample

644
1
11-23-2010 11:22 AM
KirkKuykendall
Deactivated User
Hi -

I took the Legend with Templates sample and added a button to it that lists the VisibleLayers property of the US layer.

When I first start the app it is null, even though some of the layers are checked.

If I toggle a sublayer it seems to synch for this sample.  But for another app it doesn't ever synch.

private void ListVisibleLayers_Click(object sender, RoutedEventArgs e)
{
    try
    {
        var dynLayer = MyMap.Layers["United States"] as ArcGISDynamicMapServiceLayer;
        if (dynLayer.VisibleLayers == null)
        {
            MessageBox.Show("null visiblelayers property");
        }
        else
        {
            var sb = new System.Text.StringBuilder();
            foreach (int id in dynLayer.VisibleLayers)
                sb.AppendLine(id.ToString());
            MessageBox.Show(sb.ToString());
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
0 Kudos
1 Reply
dotMorten_esri
Esri Notable Contributor
VisibleLayers = null just means "show default layers" (it's null because you didn't set it yet).
Legend is smart enough to know what layers are default and checks those on in the legend.
0 Kudos