To begin working with the ArcGIS API for Silverlight, follow these steps:
- Install prerequisites, then download and install the ArcGIS API for Silverlight. See Installation for details.
- In Visual Studio 2010, create a Silverlight application project and
with a host website.
If you are creating a new Silverlight application, in the New Silverlight Application dialog box, choose Host the Silverlight application in a new website with and a New Web project type setting of ASP.NET Web Application Project.
- Add a reference to one or more of the ArcGIS API for Silverlightassemblies in your Silverlight application project by taking the following steps:
- In Visual Studio 2010, open Solution Explorer and locate the Silverlight application project.
- Right-click the References node and click Add Reference.
- Under the .NET tab, select and add the ESRI.ArcGIS.Client assembly.
- In your Silverlight application, open a Silverlight user
control in XAML view (for example, MainPage.xaml) and add code to access and
display an ArcGIS Server map service.
For example, the following steps and code show the items necessary to add
and display a map and an ArcGIS Server cached map service.
- Add a namespace reference to the ArcGIS Silverlight schema.
- Add a Map control.
- Add an ArcGISTiledMapServerLayer in the Map element.
- On the ArcGISTiledMapServerLayer element, set the Url attribute to the REST endpoint for the ArcGIS Server cached map service.
<UserControl x:Class="SilverlightApplication.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:esri="http://schemas.esri.com/arcgis/client/2009"> <Grid x:Name="LayoutRoot"> <esri:Map x:Name="MyMap" > <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/> </esri:Map> </Grid> </UserControl>
- Compile the code and run your application. Your Silverlight application should be hosted in an HTML or page on a web server and accessed in a browser. Visual Studio's internal Web Development Server will work. If the map is blank, check the following:
- Accessing an HTML page via the file system does not allow remote map services to display within the Map control. By default, files accessed via the file system in a browser have restricted access to remote services which include ArcGIS Online services.
- To access an ArcGIS Server site on a different domain than the Silverlight application host site, the ArcGIS Server site must enable remote access to services. This is accomplished using clientaccesspolicy.xml or crossdomain.xml. In most cases, just place the XML file at the root of your website (for example, for IIS, C:\inetpub\wwwroot\).
ArcGIS Online already hosts both files to support cross-domain access for all Silverlight clients. See FAQs for more details.
For more information
To view ArcGIS API for Silverlight components in action, see the samples application.
To start building apps quickly and easily, the following options are available:
- Source code for a set of ArcGIS API for Silverlight project templates is available on GitHub.com. Download, build, customize and enjoy.
- The ArcGIS Viewer for Silverlight is a great way to quickly create rich web mapping applications using a fully interactive configuration experience. With the ArcGIS Viewer for Silverlight product, you can set up and modify an application's basemap, operational layers, tools, colors, title, logo, layout, links, and more without writing any code or editing any configuration files. The Viewer is fully extensible, so designers and developers can implement new tools and create new layouts and easily integrate them into the Viewer.