GMapControl Position property

Topics: Feature Requests
Oct 27, 2011 at 11:22 AM

I have problem with Position property in GMapControl. I can't set binding to this property because it is not DependencyProperty. Why it's not DependencyProperty?

Oct 27, 2011 at 12:32 PM

make it so ;}

Oct 28, 2011 at 11:07 PM

We are working on a friendly WPF/XAML GMapControl on the fork WPFMVVM. Check it out

Oct 31, 2011 at 1:42 PM
radioman wrote:

make it so ;}

Im afraid to crash something. :( 

Oct 31, 2011 at 1:43 PM
JLuisEstrada wrote:

We are working on a friendly WPF/XAML GMapControl on the fork WPFMVVM. Check it out

Position still not DependencyProperty.

Oct 31, 2011 at 3:51 PM

Working on it

Oct 31, 2011 at 4:47 PM

Still working on a few changes, but if you got some urgency in the implementation, remove the property Position on your GMapControl and replace it with this


/// <summary>
        /// current coordinates of the map center
        /// </summary>
        public PointLatLng Position
            get { return (PointLatLng)GetValue(PositionProperty); }
            set { SetValue(PositionProperty, value); }

        // Using a DependencyProperty as the backing store for Position.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty PositionProperty =
            DependencyProperty.Register("Position", typeof(PointLatLng), typeof(GMapControl), new UIPropertyMetadata(PointLatLng.Zero,new PropertyChangedCallback(OnPositionChanged)));

        public static void OnPositionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            GMapControl map = (GMapControl)d;
            if (map != null)
                map.Core.CurrentPosition = (PointLatLng)e.NewValue;

That should do the trick.

Oct 31, 2011 at 6:52 PM

Uploaded the code here

Also, added a sample window in the WPF Demo



Nov 1, 2011 at 11:39 AM

Thanks a lot! It works fine.

Nov 2, 2011 at 1:20 PM

I am also changed Markers field of GMapControl.

From this:


public readonly ObservableCollection<GMapMarker> Markers = new ObservableCollection<GMapMarker>();


To this:


public ObservableCollection<GMapMarker> Markers
	get { return (ObservableCollection<GMapMarker>)GetValue(MarkersProperty); } 
	set { SetValue(MarkersProperty, value); } 

public static readonly DependencyProperty MarkersProperty = DependencyProperty.Register("Markers", typeof(ObservableCollection<GMapMarker>), typeof(GMapControl));


Not tested yet.

Nov 2, 2011 at 2:26 PM
Edited Nov 2, 2011 at 2:27 PM

Markers binding doesn't work.

I write in XAML something like that:


Markers="{Binding Path=Markers, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"


In my ViewModel class i have this property:


public ObservableCollection<GMapMarker> Markers { get; private set; }


When i add markers using Markers.Add(marker) in ViewModel it doesn't actually update the map.

Any solutions?

Nov 2, 2011 at 2:43 PM
Edited Nov 2, 2011 at 2:44 PM

Also it doesn't works in code. I tried to add  marker directly on map:


Not works!

But if i change back from DependencyProperty to simple field, the same code works fine.

Whats the trick? :(

Nov 2, 2011 at 2:47 PM

because by default, map.ItemSource is set to Markers field

Nov 2, 2011 at 3:06 PM
Edited Nov 2, 2011 at 3:06 PM

Is it possible to make Markers dependency property?

Nov 2, 2011 at 3:11 PM

just set ItemSource to your dependency collection

Nov 2, 2011 at 3:54 PM
One of the changes I did first was to change the ItemsSource reference to Items reference, and managed to copy the Markers to Items, so, you can add markes with Items (in xaml), ItemsSource (through binding) or code with markers (which i dont recommend on wpf because breaks the MVVM phylosophy)

Check out our fork

Sent from my iPhone.
Excuse the typos

On 02/11/2011, at 08:11, "radioman"<> wrote:

From: radioman

just set ItemSource to your dependency collection

Nov 3, 2011 at 6:50 AM

So i found solution. I rollback all changes to Markers in GmapControl and just set binding to ItemsSource property in XAML to my Markers collection (in ViewModel). It works. Thank you guys.

<gmap:GMapControl MaxZoom="17" MinZoom="1" 
MapProvider="{Binding MapProvider}" Zoom="{Binding Zoom}" Position="{Binding Position}" 
ItemsSource="{Binding Path=Markers, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>

Nov 16, 2011 at 2:03 PM

JLuisEstrada, I found bug with Position dependency property. When i drag map Position should change, but it is not. I set breakpoint in method OnPositionChanged. It raise only when i set Position manually in my code, but not when i just drag the map. Any ideas how to fix it?

Nov 16, 2011 at 2:11 PM

try OnMapDrag

Nov 16, 2011 at 4:30 PM

I noticed that at least in the WPF control, the Markers collections seems out of place. It breaks with phylosophy of WPF (because I suppose, Markers property comes from the winforms control). So, my suggestion is to remove it and start promoting use the ItemsSource property for binding and the Items property for internal iterations

Nov 17, 2011 at 6:22 AM


I try to handle this event and OnCurrentPositionChanged event also by using EventToCommand (MVVM Light Toolkit). Binding works fine, but these events never raised.

Here is my XAML for GMapControl:


	<i:EventTrigger EventName="OnMapDrag">
		<cmd:EventToCommand Command="{Binding MapDragCommand}"/>
	<i:EventTrigger EventName="OnCurrentPositionChanged">
		<cmd:EventToCommand Command="{Binding CurrentPositionChangedCommand}"/>

Here is my code in ViewModel:

protected DelegateCommand CommandMapDrag;

public ICommand MapDragCommand
	get { return CommandMapDrag ?? (CommandMapDrag = new DelegateCommand(DragMap)); }

private void DragMap()

protected DelegateCommand CommandCurrrentPositionChanged;

public ICommand CurrentPositionChangedCommand
	get { return CommandCurrrentPositionChanged ?? (CommandCurrrentPositionChanged = new DelegateCommand(CurrentPositionChanged)); }

private void CurrentPositionChanged()