dot
Creating a Graphics layer

In the ArcGIS API for Microsoft Silverlight/WPF, Graphics layers allow you to dynamically display graphics on a Map. A Graphics layer could, 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:

When you create a Silverlight mapping application, you will usually declare Graphics layers in XAML. When specifying Graphics layers in this way, you will 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 your application. For more information, refer to the document Adding layers.

How to add a Graphics layer

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

<UserControl x:Class="SilverlightApp.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:esri="clr-namespace:ESRI.ArcGIS.Client;assembly=ESRI.ArcGIS.Client">
    <Grid x:Name="LayoutRoot" Background="White">
        
        <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>
        
    </Grid>
</UserControl>

Inside the Map's XAML element, declare a Graphics layer. 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 willl use this ID in your application's .NET code (i.e. code-behind) to get a reference to the layer. The code below 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>