How Run ArcGIS RunTime Map With C# Code on WPF

1581
1
Jump to solution
02-09-2017 12:37 PM
BehrouzHosseini
Occasional Contributor

I have a WPF application called WpfApplication1. In ManiWindow.xaml I have a

Snippet

<esri:MapView x:Name="MyMapView">            

</esri:MapView>

and in ManiWindow.xmal.cs I only have

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {

            InitializeComponent();

        }

    }
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

According to ESRI we can add the Map to the MapView as as long as we have an empty MapView has been added to the page at design time and has been given the name MyMapView (<esri:MapView x:Name="MyMapView"/>.

Now my question is how/ where should I add this code to get map running? 

// create a new Map 
var myMap = new Esri.ArcGISRuntime.Controls.Map();

// create a new layer (world street map tiled layer)
var uri = new Uri("http://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer");
var baseLayer = new Esri.ArcGISRuntime.Layers.ArcGISTiledMapServiceLayer(uri);
// (give the layer an ID so it can be found later)
baseLayer.ID = "BaseMap";

// add the layer to the Map
myMap.Layers.Add(baseLayer);

// set the initial view point
var mapPoint = new Esri.ArcGISRuntime.Geometry.MapPoint(-117.445, 33.9, 
    Esri.ArcGISRuntime.Geometry.SpatialReferences.Wgs84);
var initViewPoint = new Esri.ArcGISRuntime.Controls.ViewpointCenter(mapPoint, 250000);

myMap.InitialViewpoint = initViewPoint;

// assign the Map to the MapView's Map property
this.MyMapView.Map = myMap;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
1 Solution

Accepted Solutions
JenniferNery
Esri Regular Contributor

You can add this code after 

  InitializeComponent();

View solution in original post

0 Kudos
1 Reply
JenniferNery
Esri Regular Contributor

You can add this code after 

  InitializeComponent();
0 Kudos