Binding Map  in Custom control dependency property

722
2
05-24-2013 04:56 AM
bayramüçüncü
New Contributor III
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.
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
I don't see in your code where you put the map in the visual tree.
That might explain why the map doesnt' show up:)
0 Kudos
bayramüçüncü
New Contributor III
I don't see in your code where you put the map in the visual tree.
That might explain why the map doesnt' show up:)


Where should I placed the Map ? What I should do to appear the map?
0 Kudos