Select to view content in your preferred language

GraphicsLayer Symblol in LegendControl

1986
2
07-22-2011 01:35 PM
LanceCrumbliss
Frequent Contributor
How do you bind a symbol to the Legend Control?  I understand that this may not be possible considering that it's the graphic itself and not the GraphicsLayer that has a symbol property.  If that is the case, then what alternative approaches are there?

Lance
0 Kudos
2 Replies
DanDong
Deactivated User
Hi Lance,

If I understand your question correctly, you could assign simplerender to the symbol you use in the graphicslayer.
Here is how I did in my application:
In xaml:
<Grid.Resources>
<esri:FillSymbol x:Key="ResultsFillSymbol" Fill="#880000FF">
<esri:SimpleRenderer x:Key="selectPolygonSymbolRender"  Symbol="{StaticResource ResultsFillSymbol}"/>
</Grid.Resources>


In Code-behind:
GraphicsLayer graphicsLayer = MyMap.Layers["Selection Results"] as GraphicsLayer;
graphicsLayer.Renderer = LayoutRoot.Resources["selectPolygonSymbolRender"] as SimpleRenderer;
foreach (Graphic feature in featureSet.Features)
     {
          feature.Symbol = LayoutRoot.Resources["ResultsFillSymbol"] as FillSymbol;
          graphicsLayer.Graphics.Insert(0, feature);
     }


You also need to modify the layerids property of the legend control in code-behind:
if (!MyLegend.LayerIDs.Contains("Selection Results"))
                {
                    legendIDcount++;
                    MyLegend.LayerIDs.SetValue("Selection Results", legendIDcount);
                }
//legendIDcount is a global variable defined in the beginning.


Make sure to leave the place for the new graphicslayer. If you don't put a, b,c,d in the layerids property, it looks like new id couldn't be added.
In Xaml:
<esri:Legend x:Name="MyLegend" Map="{Binding ElementName=MyMap}" Grid.Row="2" Background="#FFFFFFCC" BorderBrush="#FFFFFFCC" HorizontalAlignment="Left" Margin="3,3" Width="260"
LayerItemsMode="Flat"  ShowOnlyVisibleLayers="True" LayerIDs="Visible Layers,a,b,c,d">


Hope this helps.
0 Kudos
LanceCrumbliss
Frequent Contributor
That works perfectly.  Thanks Shirley!

Lance
0 Kudos