<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="Geomentum.MediaReach.Modules.Map.View.MapView" 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" mc:Ignorable="d" xmlns:esri="http://schemas.esri.com/arcgis/client/2009" xmlns:local="clr-namespace:Geomentum.MediaReach.Modules.Map.View" xmlns:ViewModel="clr-namespace:Geomentum.MediaReach.Modules.Map.ViewModel"> <esri:Map x:Name="MyMap" WrapAround="True" IsLogoVisible="False" Layers="{Binding ViewModel.BaseMapLayerService}" /> </UserControl>using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Geomentum.MediaReach.Modules.Map.ViewModel; namespace Geomentum.MediaReach.Modules.Map.View { public partial class MapView : UserControl, IMapView { public MapView() { InitializeComponent(); } #region IMapView Members public IMapViewModel Model { get { return this.DataContext as MapViewModel; } set { this.DataContext = value; } } #endregion } }using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Geomentum.MediaReach.Modules.Map.View; using Microsoft.Practices.Prism.Events; using System.ComponentModel; using System.Collections.Generic; using Geomentum.MediaReach.Infrastructure.Models; namespace Geomentum.MediaReach.Modules.Map.ViewModel { public class MapViewModel : IMapViewModel, INotifyPropertyChanged { private readonly IEventAggregator eventAggregator; private ESRI.ArcGIS.Client.LayerCollection _baseMapLayerService; public IMapView View { get; set; } public MapViewModel(IMapView view, IEventAggregator eventAggregator, MediaReachMap map) { View = view; View.Model = this; BaseMapLayerService = CreateMapLayers(); this.eventAggregator = eventAggregator; } public ESRI.ArcGIS.Client.LayerCollection BaseMapLayerService { get { return this._baseMapLayerService; } set { this._baseMapLayerService = value; OnPropertyChanged("BaseMapLayerService"); } } private ESRI.ArcGIS.Client.LayerCollection CreateMapLayers() { ESRI.ArcGIS.Client.LayerCollection layers = new ESRI.ArcGIS.Client.LayerCollection(); //create the base map layer ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer baseLayer = new ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer() { ID = "BaseLayer", Url = "http://dg2k8esridev1/ArcGISDevelopment/rest/services/BaseMap/MapServer" }; layers.Add(baseLayer); return layers; } #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = this.PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } #endregion } }
Solved! Go to Solution.
Layers="{Binding BaseMapLayerService, Mode=TwoWay} Layers="{Binding BaseMapLayerService, Mode=TwoWay}
<UserControl x:Class="Forum.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esri="http://schemas.esri.com/arcgis/client/2009">
<Grid x:Name="LayoutRoot" Background="White">
<esri:Map WrapAround="True" x:Name="MyMap" Layers="{Binding Layers}"/>
</Grid>
</UserControl>
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.DataContext = new Model();
}
public class Model
{
public Model()
{
Layers = new LayerCollection();
Layers.Add(new ArcGISTiledMapServiceLayer() { Url = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" });
}
public LayerCollection Layers { get; set; }
}
}
Jennifer and Joe,
Thanks. Both worked.