Creating a graphics layer

In the ArcGIS API for Silverlight, graphics layers allow you to dynamically display graphics on a map. A graphics layer can, for example, be used to hold polygons drawn by a user or display features that satisfy a user-defined query. In the image below, a graphics layer is used to show states that have a population density of more than 200 per square mile:

Graphics layer

When you create a Silverlight mapping application, you'll usually declare graphics layers in XAML. When specifying graphics layers in this way, you'll add a GraphicsLayer element inside a Map element. Be sure to specify the graphics layer below any base layers so that the graphics will display above those layers when you run the application. For more information, see Adding layers.

Adding a graphics layer

If you have not already done so, create a Silverlight application with a map as described in Creating a map. Your Map's XAML should appear as follows:

<esri:Map x:Name="MyMap" Extent="-120, 20, -100, 40" >
  <esri:Map.Layers>
    <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" 
      Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
  </esri:Map.Layers>
 </esri:Map>

In the map's XAML element, declare a GraphicsLayer. Be sure to put it below the tiled map service layer.

<esri:Map x:Name="MyMap" Extent="-120, 20, -100, 40" >
  <esri:Map.Layers>
    <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" 
      Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
    <esri:GraphicsLayer />
  </esri:Map.Layers>
</esri:Map>

When you declare a graphics layer, you must give it an ID. You'll use this ID in your application's .NET code (that is, code-behind) to get a reference to the layer. The following code assigns the GraphicsLayer an ID of "MyGraphicsLayer":

<esri:Map x:Name="MyMap" Extent="-120, 20, -100, 40" >
  <esri:Map.Layers>
    <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" 
      Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
    <esri:GraphicsLayer ID="MyGraphicsLayer" />
  </esri:Map.Layers>
</esri:Map>
6/23/2013