How to add a dynamic map service layer

The following steps assume you have created a Windows Presentation Foundation (WPF) application in Visual Studio and are working in the Extensible Application Markup Language (XAML) view of the main page of your application.

Add a reference to ESRI.ArcGIS.Client.dll.

In XAML, add an Extensible Markup Language (XML) namespace that references the ArcGIS schema for WPF.

xmlns:esri="http://schemas.esri.com/arcgis/client/2009">

Add the Map control element to a container element in the page. In this example, the container is a Grid. Use the ESRI.ArcGIS.Client namespace identifier esri to define the namespace that contains the Map control. Give the Map control a unique name using the x:Name attribute.

<Grid x:Name="LayoutRoot" Background="White">
        <esri:Map x:Name="MyMap" >
        </esri:Map>
    </Grid>

Add an ArcGIS for Server dynamic map service layer to the map using the ArcGISDynamicMapServiceLayer element. Define the Url to the map service endpoint and include a unique ID for the layer.

<Grid x:Name="LayoutRoot" Background="White">
        <esri:Map x:Name="MyMap" >
            <esri:ArcGISDynamicMapServiceLayer ID="USA Demographic" 
                      Url="http://services.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Recent_Population_Change/MapServer"/>
        </esri:Map>
    </Grid>

Compile and run your application.

NoteNote:
  • If the map service is secured, you may need to generate a token and add it to the layer via the Token attribute. See the secure services topic for more information.
  • The Map's SnapToLevels property determines if the map will only be rendered at predefined scale levels. By default, Map.SnapToLevels is false, which allows the Map control to render map tiles between scale levels. If true, tile information from the first ArcGISTiledMapServiceLayer in the map's layer collection is used to define scale levels.
  • The background color for an ArcGISDynamicMapServiceLayer will always be transparent.
  • Use the Opacity property to define variable transparency for a layer. Layer opacity is applied on the client using the WPF platform capabilities.
1/27/2015