Learn how to create and display a scene A scene is a collection of layers that are displayed in 3D. It is typically composed of a basemap layer, data layers, and 3D data. Learn more with a basemap layer A basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more and an elevation layer An elevation layer is a layer that defines the ground height or the surface for a scene. Learn more . Set properties of the scene’s camera A camera defines the rendering viewpoint of a 3D scene in a scene view. Learn more to control the 3D perspective.

display a scene

Like a map A map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more , a scene A scene is a collection of layers that are displayed in 3D. It is typically composed of a basemap layer, data layers, and 3D data. Learn more contains layers A layer is a reference to a collection of geographic data that is used to access and display data. The data for layers are typically provided by the basemap layer service and data services. Learn more of geographic data. It contains a basemap layer A basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more and, optionally, one or more data layers A data layer is a layer that references geographic data from a file or a service and is used to visualize the data in a map or scene. Learn more . To provide a realistic view of the terrain, you can also add elevation layers An elevation layer is a layer that defines the ground height or the surface for a scene. Learn more to define the height of the surface across the scene. The 3D perspective of the scene is controlled by the scene’s camera A camera defines the rendering viewpoint of a 3D scene in a scene view. Learn more , which defines the position of the scene observer in 3D space.

In this tutorial, you create and display a scene A scene is a collection of layers that are displayed in 3D. It is typically composed of a basemap layer, data layers, and 3D data. Learn more using the imagery basemap layer A basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more . The surface of the scene is defined with an elevation layer An elevation layer is a layer that defines the ground height or the surface for a scene. Learn more and the camera A camera defines the rendering viewpoint of a 3D scene in a scene view. Learn more is positioned to display an area of the Santa Monica Mountains in the scene view A scene view is a user interface that displays scene layers and graphics in 3D. It uses a camera to control the visible area of the scene and supports user interactions such as pan, zoom, tilt, and rotate. Learn more .

The scene and code will be used as the starting point for other 3D tutorials.

Prerequisites

Before starting this tutorial:

Optionally, you may want to install the ArcGIS Maps SDK for .NET to get access to project templates in Visual Studio (Windows only) and offline copies of the NuGet packages.

Set up authentication

To access the secure ArcGIS location services ArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more used in this tutorial, you must implement API key authentication API key authentication is a type of authentication that uses an API key to authenticate requests to ArcGIS services and secure portal items. Learn more or user authentication User authentication is a type of authentication that allows users with an ArcGIS account to sign into an application and allow it to access ArcGIS content, services, and resources on their behalf. The typical authorization protocol used is OAuth2.0. Learn more using an ArcGIS Location Platform An ArcGIS Location Platform account, formerly known as an ArcGIS Developer account, is an identity associated with an ArcGIS Location Platform subscription. Learn more or an ArcGIS Online An ArcGIS Online account, also known as an ArcGIS Organization account, is an identity associated with an ArcGIS Online subscription. It can be used to access ArcGIS tools and develop applications with ArcGIS location services for an organization. Learn more account.

To complete this tutorial, click on the tab in the switcher below for your authentication type of choice, either API key authentication or User authentication.

Create a new API key access token An access token is an authorization string that provides access to secure ArcGIS content, data, and services. Its capabilities are determined by the privileges it supports. It is obtained by implementing API key authentication, User authentication, or App authentication. Learn more with privileges Privileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. Learn more to access the secure resources used in this tutorial.

  1. Complete the Create an API key tutorial and create an API key with the following privilege(s) Privileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. Learn more :

    • Privileges
      • Location services > Basemaps
  2. Copy and paste the API key access token into a safe location. It will be used in a later step.

Develop or download

You have two options for completing this tutorial:

  1. Option 1: Develop the code or
  2. Option 2: Download the completed solution

Option 1: Develop the code

Create a new Visual Studio Project

ArcGIS Maps SDK for .NET supports apps for Windows Presentation Framework (WPF), Windows UI Library (WinUI), and .NET MAUI. The instructions for this tutorial are specific to creating a WPF .NET project using Visual Studio for Windows.

  1. Start Visual Studio and create a new project.

    • In the Visual Studio start screen, click Create a new project.
    • Choose the WPF App (.NET) template for C#, then click Next.
    • Provide required values in the Configure your new project panel:
      • Project name: DisplayAScene
      • Location: choose a folder
    • Click Create to create the project.

Add a reference to the API

  1. Add a reference to the API by installing a NuGet package.

    • In Solution Explorer, right-click Dependencies and choose Manage NuGet Packages.
    • In the NuGet Package Manager window, ensure the selected Package source is nuget.org (upper-right).
    • Select the Browse tab and search for ArcGIS Maps SDK.
    • In the search results, select the appropriate package for your platform. For this tutorial project, choose the Esri.ArcGISRuntime.WPF NuGet package.
    • Confirm the Latest stable version of the package is selected in the Version dropdown.
    • Click Install.
    • The Preview Changes dialog confirms any package(s) dependencies or conflicts. Review the changes and click Apply to continue installing the packages.
    • Review the license information on the License Acceptance dialog and click I Accept to add the package(s) to your project.
    • In the Visual Studio Output window, ensure the packages were successfully installed. If you see an error about the target Windows version, you will fix that in the next step.
    • Close the NuGet Package Manager window.
  2. You may see an error like this in the Visual Studio Error List: The 'Esri.ArcGISRuntime.WPF' nuget package cannot be used to target 'net8.0-windows'. Target 'net8.0-windows10.0.19041.0' or later instead.. If so, follow these steps to address it.

    • In Solution Explorer, right-click the project entry in the tree view and choose Edit Project File.
    • Update the <TargetFramework> element with net8.0-windows10.0.19041.0 (or higher).
    <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
    <UseWPF>true</UseWPF>
    </PropertyGroup>
    • Save the project file and close it.

Create a view model to store app logic

Since this app builds the foundation to be used in several following tutorials, it’s good to build it with a solid design.

  1. Add a new class that defines a view model for the project.

    • Click Project > Add Class ….
    • Name the new class SceneViewModel.cs.
    • Click Add to create the new class and add it to the project.
    • The new class will open in Visual Studio.
  2. Add required using statements to the view model.

    SceneViewModel.cs
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Esri.ArcGISRuntime.Geometry;
    using Esri.ArcGISRuntime.Mapping;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
  3. Implement the INotifyPropertyChanged interface in the SceneViewModel class.

    SceneViewModel.cs
    namespace DisplayAScene
    {
    class SceneViewModel : INotifyPropertyChanged
    {
  4. Inside the SceneViewModel class, add code to implement the PropertyChanged event.

    SceneViewModel.cs
    25 collapsed lines
    // Copyright 2021 Esri
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    // https://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Esri.ArcGISRuntime.Geometry;
    using Esri.ArcGISRuntime.Mapping;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    namespace DisplayAScene
    {
    class SceneViewModel : INotifyPropertyChanged
    {
    public event PropertyChangedEventHandler? PropertyChanged;
    protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
    }
    2 collapsed lines
    }
  5. Define a new property on the view model called Scene that exposes an Scene object. When the property is set, call OnPropertyChanged.

    SceneViewModel.cs
    25 collapsed lines
    // Copyright 2021 Esri
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    // https://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Esri.ArcGISRuntime.Geometry;
    using Esri.ArcGISRuntime.Mapping;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    namespace DisplayAScene
    {
    class SceneViewModel : INotifyPropertyChanged
    {
    public event PropertyChangedEventHandler? PropertyChanged;
    protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
    private Scene? _scene;
    public Scene? Scene
    {
    get { return _scene; }
    set
    {
    _scene = value;
    OnPropertyChanged();
    }
    }
    }
    2 collapsed lines
    }
  6. Add a function to the SceneViewModel class called SetupScene. Start the function by creating a new Scene using the ArcGISImageryStandard field of the BasemapStyle enum.

    SceneViewModel.cs
    45 collapsed lines
    // Copyright 2021 Esri
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    // https://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Esri.ArcGISRuntime.Geometry;
    using Esri.ArcGISRuntime.Mapping;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    namespace DisplayAScene
    {
    class SceneViewModel : INotifyPropertyChanged
    {
    public event PropertyChangedEventHandler? PropertyChanged;
    protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
    private Scene? _scene;
    public Scene? Scene
    {
    get { return _scene; }
    set
    {
    _scene = value;
    OnPropertyChanged();
    }
    }
    private void SetupScene()
    {
    // Create a new scene with an imagery basemap.
    Scene scene = new Scene(BasemapStyle.ArcGISImageryStandard);
    }
    4 collapsed lines
    }
    }
  7. Create an ElevationSource to define the base surface for the scene.

    SceneViewModel.cs
    48 collapsed lines
    // Copyright 2021 Esri
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    // https://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Esri.ArcGISRuntime.Geometry;
    using Esri.ArcGISRuntime.Mapping;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    namespace DisplayAScene
    {
    class SceneViewModel : INotifyPropertyChanged
    {
    public event PropertyChangedEventHandler? PropertyChanged;
    protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
    private Scene? _scene;
    public Scene? Scene
    {
    get { return _scene; }
    set
    {
    _scene = value;
    OnPropertyChanged();
    }
    }
    private void SetupScene()
    {
    // Create a new scene with an imagery basemap.
    Scene scene = new Scene(BasemapStyle.ArcGISImageryStandard);
    // Create an elevation source to show relief in the scene.
    string elevationServiceUrl = "http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
    ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource(new Uri(elevationServiceUrl));
    // Create a Surface with the elevation data.
    Surface elevationSurface = new Surface();
    elevationSurface.ElevationSources.Add(elevationSource);
    // Add an exaggeration factor to increase the 3D effect of the elevation.
    elevationSurface.ElevationExaggeration = 2.5;
    // Apply the surface to the scene.
    scene.BaseSurface = elevationSurface;
    6 collapsed lines
    }
    }
    }
  8. Define the initial viewpoint for the scene using a Camera and a point in the scene.

    SceneViewModel.cs
    62 collapsed lines
    // Copyright 2021 Esri
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    // https://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Esri.ArcGISRuntime.Geometry;
    using Esri.ArcGISRuntime.Mapping;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    namespace DisplayAScene
    {
    class SceneViewModel : INotifyPropertyChanged
    {
    public event PropertyChangedEventHandler? PropertyChanged;
    protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
    private Scene? _scene;
    public Scene? Scene
    {
    get { return _scene; }
    set
    {
    _scene = value;
    OnPropertyChanged();
    }
    }
    private void SetupScene()
    {
    // Create a new scene with an imagery basemap.
    Scene scene = new Scene(BasemapStyle.ArcGISImageryStandard);
    // Create an elevation source to show relief in the scene.
    string elevationServiceUrl = "http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
    ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource(new Uri(elevationServiceUrl));
    // Create a Surface with the elevation data.
    Surface elevationSurface = new Surface();
    elevationSurface.ElevationSources.Add(elevationSource);
    // Add an exaggeration factor to increase the 3D effect of the elevation.
    elevationSurface.ElevationExaggeration = 2.5;
    // Apply the surface to the scene.
    scene.BaseSurface = elevationSurface;
    // Create a point that defines the observer's (camera) initial location in the scene.
    // The point defines a longitude, latitude, and altitude of the initial camera location.
    MapPoint cameraLocation = new MapPoint(-118.804, 33.909, 5330.0, SpatialReferences.Wgs84);
    // Create a Camera using the point, the direction the camera should face (heading), and its pitch and roll (rotation and tilt).
    Camera sceneCamera = new Camera(locationPoint: cameraLocation,
    heading: 355.0,
    pitch: 72.0,
    roll: 0.0);
    // Create the initial point to center the camera on (the Santa Monica mountains in Southern California).
    // Longitude=118.805 degrees West, Latitude=34.027 degrees North
    MapPoint sceneCenterPoint = new MapPoint(-118.805, 34.027, SpatialReferences.Wgs84);
    // Set an initial viewpoint for the scene using the camera and observation point.
    Viewpoint initialViewpoint = new Viewpoint(sceneCenterPoint, sceneCamera);
    scene.InitialViewpoint = initialViewpoint;
    6 collapsed lines
    }
    }
    }
  9. Set the SceneViewModel.Scene property with the scene you’ve created.

    SceneViewModel.cs
    79 collapsed lines
    // Copyright 2021 Esri
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    // https://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Esri.ArcGISRuntime.Geometry;
    using Esri.ArcGISRuntime.Mapping;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    namespace DisplayAScene
    {
    class SceneViewModel : INotifyPropertyChanged
    {
    public event PropertyChangedEventHandler? PropertyChanged;
    protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
    private Scene? _scene;
    public Scene? Scene
    {
    get { return _scene; }
    set
    {
    _scene = value;
    OnPropertyChanged();
    }
    }
    private void SetupScene()
    {
    // Create a new scene with an imagery basemap.
    Scene scene = new Scene(BasemapStyle.ArcGISImageryStandard);
    // Create an elevation source to show relief in the scene.
    string elevationServiceUrl = "http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
    ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource(new Uri(elevationServiceUrl));
    // Create a Surface with the elevation data.
    Surface elevationSurface = new Surface();
    elevationSurface.ElevationSources.Add(elevationSource);
    // Add an exaggeration factor to increase the 3D effect of the elevation.
    elevationSurface.ElevationExaggeration = 2.5;
    // Apply the surface to the scene.
    scene.BaseSurface = elevationSurface;
    // Create a point that defines the observer's (camera) initial location in the scene.
    // The point defines a longitude, latitude, and altitude of the initial camera location.
    MapPoint cameraLocation = new MapPoint(-118.804, 33.909, 5330.0, SpatialReferences.Wgs84);
    // Create a Camera using the point, the direction the camera should face (heading), and its pitch and roll (rotation and tilt).
    Camera sceneCamera = new Camera(locationPoint: cameraLocation,
    heading: 355.0,
    pitch: 72.0,
    roll: 0.0);
    // Create the initial point to center the camera on (the Santa Monica mountains in Southern California).
    // Longitude=118.805 degrees West, Latitude=34.027 degrees North
    MapPoint sceneCenterPoint = new MapPoint(-118.805, 34.027, SpatialReferences.Wgs84);
    // Set an initial viewpoint for the scene using the camera and observation point.
    Viewpoint initialViewpoint = new Viewpoint(sceneCenterPoint, sceneCamera);
    scene.InitialViewpoint = initialViewpoint;
    // Set the view model "Scene" property.
    this.Scene = scene;
    6 collapsed lines
    }
    }
    }
  10. Add a constructor to the class that calls SetupScene when a new SceneViewModel is created.

    SceneViewModel.cs
    22 collapsed lines
    // Copyright 2021 Esri
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    // https://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Esri.ArcGISRuntime.Geometry;
    using Esri.ArcGISRuntime.Mapping;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    namespace DisplayAScene
    {
    class SceneViewModel : INotifyPropertyChanged
    {
    public SceneViewModel()
    {
    SetupScene();
    }
    64 collapsed lines
    public event PropertyChangedEventHandler? PropertyChanged;
    protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
    private Scene? _scene;
    public Scene? Scene
    {
    get { return _scene; }
    set
    {
    _scene = value;
    OnPropertyChanged();
    }
    }
    private void SetupScene()
    {
    // Create a new scene with an imagery basemap.
    Scene scene = new Scene(BasemapStyle.ArcGISImageryStandard);
    // Create an elevation source to show relief in the scene.
    string elevationServiceUrl = "http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
    ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource(new Uri(elevationServiceUrl));
    // Create a Surface with the elevation data.
    Surface elevationSurface = new Surface();
    elevationSurface.ElevationSources.Add(elevationSource);
    // Add an exaggeration factor to increase the 3D effect of the elevation.
    elevationSurface.ElevationExaggeration = 2.5;
    // Apply the surface to the scene.
    scene.BaseSurface = elevationSurface;
    // Create a point that defines the observer's (camera) initial location in the scene.
    // The point defines a longitude, latitude, and altitude of the initial camera location.
    MapPoint cameraLocation = new MapPoint(-118.804, 33.909, 5330.0, SpatialReferences.Wgs84);
    // Create a Camera using the point, the direction the camera should face (heading), and its pitch and roll (rotation and tilt).
    Camera sceneCamera = new Camera(locationPoint: cameraLocation,
    heading: 355.0,
    pitch: 72.0,
    roll: 0.0);
    // Create the initial point to center the camera on (the Santa Monica mountains in Southern California).
    // Longitude=118.805 degrees West, Latitude=34.027 degrees North
    MapPoint sceneCenterPoint = new MapPoint(-118.805, 34.027, SpatialReferences.Wgs84);
    // Set an initial viewpoint for the scene using the camera and observation point.
    Viewpoint initialViewpoint = new Viewpoint(sceneCenterPoint, sceneCamera);
    scene.InitialViewpoint = initialViewpoint;
    // Set the view model "Scene" property.
    this.Scene = scene;
    }
    }
    }

Your SceneViewModel is complete!

An advantage to using the MVVM design pattern is that you can reuse code from a view model. Because this API has a nearly-standard API surface across platforms, a view model written for one app typically works on all supported .NET platforms.

Set developer credentials

To allow your app users to access ArcGIS Location Services ArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more , use the developer credentials that you created in the Set up authentication step to authenticate requests for resources.

  1. In the Solution Explorer, expand the node for App.xaml, and double-click App.xaml.cs to open it.

  2. In the App class, add an override for the OnStartup() function to set the ApiKey property on ArcGISRuntimeEnvironment.

    App.xaml.cs
    public partial class App : Application
    {
    protected override void OnStartup(StartupEventArgs e)
    {
    base.OnStartup(e);
    // Set the access token for ArcGIS Maps SDK for .NET.
    Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "YOUR_ACCESS_TOKEN";
    }
    }
    }
  3. Replace “YOUR_ACCESS_TOKEN” with the API key access token you created earlier.

  4. Save and close the App.xaml.cs file.

Best Practice: The access token is stored directly in the code as a convenience for this tutorial. Do not store credentials directly in source code in a production environment.

Next, set up a view in your project to consume the view model.

Add a scene view

A SceneView control is used to display a Scene. You will add a scene view to your project UI and wire it up to consume the scene that is defined on SceneViewModel.

  1. Add required XML namespace and resource declarations.

    MainWindow.xaml
    <Window x:Class="DisplayAScene.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:DisplayAScene"
    xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
    <local:SceneViewModel x:Key="SceneViewModel" />
    </Window.Resources>
    6 collapsed lines
    <Grid>
    </Grid>
    </Window>
  2. Add a SceneView control to MainWindow.xaml and bind it to the SceneViewModel.

    MainWindow.xaml
    14 collapsed lines
    <Window x:Class="DisplayAScene.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:DisplayAScene"
    xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
    <local:SceneViewModel x:Key="SceneViewModel" />
    </Window.Resources>
    <Grid>
    <esri:SceneView x:Name="MainSceneView"
    Scene="{Binding Scene, Source={StaticResource SceneViewModel}}" />
    </Grid>
    2 collapsed lines
    </Window>

Run the app

Click Debug > Start Debugging (or press <F5> on the keyboard) to run the app. If your app uses user authentication, enter your ArcGIS Online credentials when prompted.

You should see a scene A scene is a collection of layers that are displayed in 3D. It is typically composed of a basemap layer, data layers, and 3D data. Learn more with the topographic basemap layer A basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more centered on the Santa Monica Mountains in California. Double-click, drag, and scroll the mouse wheel over the scene view to explore the scene.

Alternatively, you can download the tutorial solution, as follows.

Option 2: Download the solution

  1. Click the Download solution link in the right-hand panel of the page.

  2. Unzip the file to a location on your machine.

  3. Open the .sln file in Visual Studio.

Since the downloaded solution does not contain authentication credentials, you must add the developer credentials that you created in the Set up authentication section.

Set developer credentials in the solution

To allow your app users to access ArcGIS location services ArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more , use the developer credentials that you created in the Set up authentication step to authenticate requests for resources.

  1. In Visual Studio, in the Solution Explorer, click App.xaml.cs to open the file.

  2. Set the ArcGISEnvironment.ApiKey property with your API key access token.

    App.xaml.cs
    protected override void OnStartup(StartupEventArgs e)
    {
    base.OnStartup(e);
    // Set the access token for ArcGIS Maps SDK for .NET.
    Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "YOUR_ACCESS_TOKEN";
    // Call a function to set up the AuthenticationManager for OAuth.
    UserAuth.ArcGISLoginPrompt.RegisterOAuthConfig();
    }
  3. Remove the code that sets up user authentication.

    App.xaml.cs
    protected override void OnStartup(StartupEventArgs e)
    {
    base.OnStartup(e);
    // Set the access token for ArcGIS Maps SDK for .NET.
    Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "YOUR_ACCESS_TOKEN";
    // Call a function to set up the AuthenticationManager for OAuth.
    UserAuth.ArcGISLoginPrompt.RegisterOAuthConfig();
    }

Best Practice: The access token is stored directly in the code as a convenience for this tutorial. Do not store credentials directly in source code in a production environment.

Run the app

Click Debug > Start Debugging (or press <F5> on the keyboard) to run the app. If your app uses user authentication, enter your ArcGIS Online credentials when prompted.

You should see a map A map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more with the topographic basemap layer A basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more centered on the Santa Monica Mountains in California. Double-click, drag, and scroll the mouse wheel over the map view to explore the map.

What’s next?

Learn how to use additional API features, ArcGIS location services, and ArcGIS tools in these tutorials: