Click or drag to resize
Code Example - InitialMapExtentCode

Shows how to set the initial extent of the map (Map.InitialExtent) in code.

Code Example
Initial Map Extent Code

This section contains selected code files from a Visual Studio project that emphasize specific ArcGIS Runtime SDK (Windows Desktop) features. For example: some code examples may accomplish the bulk of the work as a configuration property in the .xaml file and hence only the .xaml file will be shown in detail below. In other code examples, the .xaml is used to define the configuration of graphical elements for the application but the application logic is performed in the code behind, hence you may see both the .xaml and .cs/.vb files shown in detail below.

<Window x:Class="InitialMapExtentCode.MainWindow"
        Height="600" Width="800">


            <!-- Display the MapView.Extent to the user. -->
            <TextBlock Text="Current Map.Extent:" HorizontalAlignment="Center"/>
            <TextBox x:Name="myCoords" Height="25" TextAlignment="Center"/>

            <!-- Add a MapView Control. -->
            <esri:MapView x:Name="MapView1" Height="575">

                <!-- Add a Map. -->
                <esri:Map x:Name="MyMap"  >

                    <!-- Add an ArcGISTiledMapServiceLayer. -->
                        ServiceUri="" />




SPECIAL NOTE: The XAML displayed above comes from a C# project. If you are a VB.NET developer, you will need to modify the text for the x:Class namespace from "InitialMapExtentCode.MainWindow" to be just "MainWindow".

// NOTE: Shows how to set the initial extent of the map (Map.InitialExtent) in code.

namespace InitialMapExtentCode
    public partial class MainWindow : System.Windows.Window
        public MainWindow()

            // Define a SpatialReference using the WKID of 102100 (i.e. Web Mercator). Note that the 
            // SpatialReference.Create is a static/Shared function and hence you do not use the 'new'
            // keyword. 
            Esri.ArcGISRuntime.Geometry.SpatialReference mySpatialReference = null;
            mySpatialReference = Esri.ArcGISRuntime.Geometry.SpatialReference.Create(102100);

            // Create an envelope that has the spatial extent of the Rochester, NY region using the Web Mercator
            // SpatialReference.
            Esri.ArcGISRuntime.Geometry.Envelope myEnvelope = null;
            myEnvelope = new Esri.ArcGISRuntime.Geometry.Envelope(-8669706, 5265422, -8538812, 5361422, mySpatialReference);

            // Set the initial extent of the Map (via InitialViewpoint Property) the to that of our Envelope.
            MapView1.Map.InitialViewpoint = new Esri.ArcGISRuntime.Controls.Viewpoint(myEnvelope);

            // Define an Event Handler to fire each time the Map.Extent changes.
            MapView1.ExtentChanged += myMap_ExtentChanged;


        private void myMap_ExtentChanged(object sender, System.EventArgs e)

            // Display the current Map.Extent back to the user in the application.
            myCoords.Text = MapView1.Extent.ToString();