Select to view content in your preferred language

esriLegend, reload in code behind

935
3
05-12-2011 07:23 AM
PLadd
by
Frequent Contributor
I'm using the esriLegend control.  I'm using LayerIDs in xaml and restricting the list.  When user clicks a radio button, I want to change the layers in legend (layers are already in map but not in legend) in code behind.  I haven't gotten very far:

case "Time Viewer":
    String[] aerialList = {"Parcels, Aerials 2002, Aerials 2005, Aerials 2009"};
    esriLegend.LayerIDs = aerialList ;

The legend goes blank.  I tried adding esriLegend.Refresh() but that didn't work.  Any thoughts?

Sincerely,
KnowsEnoughToBeDangerous
0 Kudos
3 Replies
PLadd
by
Frequent Contributor
Here's one more thing I tried. 

The original list is this:

LayerIDs="Parcels, Other Features, Buildings"

If I do this in code behind, it works OK:

String[] aerialList = {"Parcels"};
esriLegend.LayerIDs = aerialList ;
esriLegend.Refresh();

So it looks I can reduce the original list but not add to it.  Any thoughts?
0 Kudos
PatrickBrooke
Emerging Contributor
I tried your method and I am able to add and remove layers to the legend, so long as they are already included in the xaml side. I am not having the same problem using the same method you display.

I did this using ESRI's legend sample and your code:
 private void remAddLayers()
        {
            string[] aerialList = {"Points of Interest", "United States"};
            esriLegend.LayerIDs = aerialList;
            esriLegend.Refresh();
        }


Xaml:
 <esri:Map x:Name="MyMap" Extent="-15000000,2000000,-7000000,8000000" MouseLeftButtonDown="MyMap_MouseLeftButtonDown">
            <esri:ArcGISTiledMapServiceLayer ID="Street Map" 
                    Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
            <esri:ArcGISDynamicMapServiceLayer ID="United States" Opacity="0.6" 
                    Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"/>
            <esri:FeatureLayer ID="Points of Interest" 
                    Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer/0" />
        </esri:Map>

 <esri:Legend x:Name="esriLegend" Map="{Binding ElementName=MyMap}"  
                         LayerIDs="Points of Interest"
                         LayerItemsMode="Tree" 
                         ShowOnlyVisibleLayers="False">
                         


And I was able to add the United States layer.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
String[] aerialList = {"Parcels, Aerials 2002, Aerials 2005, Aerials 2009"};

The mistake is there. You have to initialize your object with a list of strings, not with one string containing a list.
So the code should be :
String[] aerialList = {"Parcels", "Aerials 2002", "Aerials 2005", "Aerials 2009"};


Note : the value converter allowing to transform a string containing a list to a list of strings is only working in XAML. The converter is not being called when you set the property by code.
0 Kudos