I wanna a map bindable control to use in MVVM pattern but I have a problem.I created a class like this.
public class MapControl : Control
{
public static readonly DependencyProperty MapProperty =
DependencyProperty.RegisterAttached(
"Map",
typeof(Map),
typeof(MapControl),
new PropertyMetadata(OnMapChanged));
[Bindable(true)]
public Map Map
{
get { return (Map)GetValue(MapProperty); }
set { SetValue(MapProperty, value); }
}
private static void OnMapChanged(DependencyObject depObject, DependencyPropertyChangedEventArgs e)
{
}
}
And in my ViewModel I created a new Map like this.
public class MainPageViewModel:INotifyPropertyChanged
{
private Map map;
public MainPageViewModel()
{
Map startMap = new Map();
startMap.Layers.Add(new ArcGISTiledMapServiceLayer { Url = "http://....." });
Map = startMap;
}
public Map Map
{
get
{
return map;
}
set
{
map = value;
OnPropertyChanged("Map");
}
}
when I put breakpoints Map object in ViewModel or in Custom MapControl, Everything is working fine.
<Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource ViewModel}}">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<esriCustom:MapControl Map="{Binding Map}" Grid.Column="0">
</esriCustom:MapControl>
</Grid>
I finally bind the ViewModel object Map to View MapControl. But nothing is appeared.