The issue with the screen shot is that under the Basemap service, none of the layers are showing legend icons. I uploaded another screen shot illustrating the differences between the unsecured service ("United States") and the secured service ("Basemap").I have replicated this same problem using QueryLegendInfos(). If I use that with an unsecure ArcGISDynamicMapServiceLayer or with a FeatureLayer (whether secure or not) I am able to obtain legend icons, but if I use it with a secure ArcGISDynamicMapServiceLayer, there are no legend icons returned. LegendItemInfos is always null.My callback function (admittedly not pretty, but I wrote it quickly for testing purposes) is below.private void callback(LayerLegendInfo layerLegendInfo, TreeViewItem treeViewItem)
{
// group/parent layer
if (layerLegendInfo.LayerLegendInfos != null)
{
TreeViewItem tviGroup = new TreeViewItem() { Header = layerLegendInfo.LayerName };
if (treeViewItem == null)
{
treeViewItem = tviGroup;
stackPanelTest.Children.Add(treeViewItem);
}
else
{
treeViewItem.Items.Add(tviGroup);
}
foreach (LayerLegendInfo info in layerLegendInfo.LayerLegendInfos)
callback(info, tviGroup);
}
// feature layer with legend icons
else if (layerLegendInfo.LegendItemInfos != null)
foreach (LegendItemInfo info in layerLegendInfo.LegendItemInfos)
{
StackPanel stackPanelImage = new StackPanel() { Orientation = Orientation.Horizontal };
stackPanelImage.Children.Add(new TextBlock() { Text = "2-"+layerLegendInfo.LayerName, Margin = new Thickness(5) });
stackPanelImage.Children.Add(new Image() { Source = info.ImageSource });
treeViewItem.Items.Add(stackPanelImage);
}
// feature layer with no legend icons returned
else
{
StackPanel stackPanelImage = new StackPanel() { Orientation = Orientation.Horizontal };
stackPanelImage.Children.Add(new TextBlock() { Text = "3-"+layerLegendInfo.LayerName, Margin = new Thickness(5) });
treeViewItem.Items.Add(stackPanelImage);
}
}