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
<SPAN class="keyword token">namespace</SPAN> WpfApplication1
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">/// <summary></SPAN>
<SPAN class="comment token">/// Interaction logic for MainWindow.xaml</SPAN>
<SPAN class="comment token">/// </summary></SPAN>
<SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">partial</SPAN> <SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">MainWindow</SPAN> <SPAN class="punctuation token">:</SPAN> Window
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">public</SPAN> <SPAN class="token function">MainWindow</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="token function">InitializeComponent</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>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?
<SPAN class="comment token">// create a new Map </SPAN>
<SPAN class="keyword token">var</SPAN> myMap <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Controls<SPAN class="punctuation token">.</SPAN>Map</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// create a new layer (world street map tiled layer)</SPAN>
<SPAN class="keyword token">var</SPAN> uri <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Uri</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fservices.arcgisonline.com%2Farcgis%2Frest%2Fservices%2FWorld_Street_Map%2FMapServer" target="_blank">http://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer</A><SPAN>"</SPAN></SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> baseLayer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Layers<SPAN class="punctuation token">.</SPAN>ArcGISTiledMapServiceLayer</SPAN><SPAN class="punctuation token">(</SPAN>uri<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// (give the layer an ID so it can be found later)</SPAN>
baseLayer<SPAN class="punctuation token">.</SPAN>ID <SPAN class="operator token">=</SPAN> <SPAN class="string token">"BaseMap"</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// add the layer to the Map</SPAN>
myMap<SPAN class="punctuation token">.</SPAN>Layers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>baseLayer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// set the initial view point</SPAN>
<SPAN class="keyword token">var</SPAN> mapPoint <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Geometry<SPAN class="punctuation token">.</SPAN>MapPoint</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">117.445</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">33.9</SPAN><SPAN class="punctuation token">,</SPAN>
Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Geometry<SPAN class="punctuation token">.</SPAN>SpatialReferences<SPAN class="punctuation token">.</SPAN>Wgs84<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> initViewPoint <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Controls<SPAN class="punctuation token">.</SPAN>ViewpointCenter</SPAN><SPAN class="punctuation token">(</SPAN>mapPoint<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">250000</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
myMap<SPAN class="punctuation token">.</SPAN>InitialViewpoint <SPAN class="operator token">=</SPAN> initViewPoint<SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// assign the Map to the MapView's Map property</SPAN>
<SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>MyMapView<SPAN class="punctuation token">.</SPAN>Map <SPAN class="operator token">=</SPAN> myMap<SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>