To work with ArcGIS Runtime SDK for .NET in your Visual Studio (Windows or Mac) project, you need to add the appropriate ArcGIS Runtime API NuGet package and also add any required XML namespace references in your XAML. This process is not unique to ArcGIS Runtime SDK for .NET, you may follow a similar workflow for other APIs you want to use in your project.
The following steps guide you through creating a new Visual Studio project for your WPF app. You will also learn how to add the proper references for working with ArcGIS Runtime SDK for .NET classes. You can follow these same basic steps for every ArcGIS Runtime SDK for .NET project you create.
ArcGIS Runtime SDK for .NET Visual Studio Extension provides a project template (for use in Visual Studio on Windows only) for creating your mapping app, called ArcGIS Runtime Application. See the Install the SDK topic for information about installing the ArcGIS Runtime SDK for .NET Visual Studio Extension.
Create a WPF app
Use Visual Studio to create a WPF app.
- Open a supported version of Microsoft Visual Studio.
- Choose File > New > Project (or click New Project on the Start page) to create a project.
- Click Windows > Classic Desktop > WPF Application in the New Project dialog box template list.
If you create your app using the ArcGIS Runtime App template, you do not need to complete the rest of the steps described in this topic. Creating your project from the template adds the appropriate NuGet packages and references as well as a page with a map view containing a single base layer.
- Choose a folder location for your new project and give it a name.
- Click OK to create the project.
Your solution opens in Visual Studio and contains a WPF window called MainWindow.xaml.
Add ArcGIS Runtime SDK NuGet packages
ArcGIS Runtime SDK NuGet packages are hosted on NuGet.org. If you have an internet connection, you can access these packages and add them to your Visual Studio (Windows or Mac) project without having to install anything locally. If you've installed the ArcGIS Runtime SDK for .NET Visual Studio Extension (Windows only), then you also have these packages available in a local NuGet package source (called Esri).
- Open the NuGet Package Manager (Project > Manage NuGet Packages, for example).
- Choose the Browse tab in the manager. Choose the Esri package source to add locally installed packages. Otherwise, choose the online nuget.org package source. NuGet hosts around 100,000 packages, so you'll need to use the Search text box to locate the ArcGIS Runtime packages if using the online package source.
- To locate the ArcGIS Runtime packages, type ArcGIS Runtime in the Search text box. You will see several matches (for various versions and platforms).
- Select a version 100.2.0 package for your platform. Click Install to add the package to your project.
- Choose OK to proceed with the installation and then I Accept to accept the license agreement.
After adding the package, you'll be able to work with the components in ArcGIS Runtime for .NET API in your code.
Add XML namespace references
In addition to the project reference you made to the ArcGIS Runtime assembly, you must also add an XML namespace reference in your XAML page in order to add the MapView control to your page.
- Open the MainWindow.xaml file in the Visual Studio designer.
- Go to the XAML view of the designer and add the following XML namespace reference to the WindowContentPage XAML element. Visual Studio offers Intellisense to help complete the URL portion of the statement.
- You can now use the XML prefix you've defined to work with ArcGIS Runtime SDK in your XAML. The following code sample defines a new MapView control and Map containing a single ArcGISTiledLayer basemap layer.
<esri:MapView> <esri:Map> <esri:Map.Basemap> <esri:Basemap Name="Basemap"> <esri:ArcGISTiledLayer Name="World Topographic" Source="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/> </esri:Basemap> </esri:Map.Basemap> </esri:Map> </esri:MapView>
You can display a map in your app by ...
- Defining it entirely with XAML
- Use data binding to associate the MapView control defined in XAML to a Map in another class (a ViewModel using the MVVM pattern, for example)
- Define the MapView in your XAML and assign a map in your code behind, as shown in the following example.
// create a new Map with a streets basemap var map = new Map(Basemap.CreateStreets()); // assign the map to MyMapView (MapView control) MyMapView.Map = map;
The process described in this topic is generally the first thing you'll do for each ArcGIS Runtime SDK for .NET project you create from a standard Visual Studio template. The details for adding these references differ slightly between SDK platforms.