Note that there are some explanatory texts on larger screens.

plurals
  1. POMapOverlay binding not working
    primarykey
    data
    text
    <p>I'm trying to get a map overlay working on Windows Phone 8 using an MVVM code structure. I can't seem to get the GeoCoordinate property of the MapOverlay to bind to my ViewModel properly and I can't work out why.</p> <p>The XAML as stands is:</p> <p>Header:</p> <pre><code>xmlns:maps="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps" </code></pre> <p>Code:</p> <pre><code>&lt;maps:Map x:Name="Map" ZoomLevel="6" Height="500" Width="500" CartographicMode="Terrain" Center="{Binding MapCenter, Converter={StaticResource GpsCoordinateConverter}, Mode=TwoWay}"&gt; &lt;maps:Map.Layers&gt; &lt;maps:MapLayer&gt; &lt;maps:MapOverlay PositionOrigin="1,1" GeoCoordinate="{Binding MapCenter, Converter={StaticResource GpsCoordinateConverter}, Mode=OneWay}"&gt; &lt;Ellipse Fill="Blue" Height="20" Width="20" Opacity="50" /&gt; &lt;/maps:MapOverlay&gt; &lt;/maps:MapLayer&gt; &lt;/maps:Map.Layers&gt; &lt;/maps:Map&gt; </code></pre> <p>The <code>GpsCoordinateConverter</code> is just a very simple class which changes the data type from my View Model into the <code>System.Device.Location.GeoCoordinate</code> that the map control expects. The center of the map binding is working fine, but the GeoCoordinate on the overlay will not bind and the blue circle just sits in the top left of the map.</p> <p>I've verified the PropertyChanged event is firing for my model, both through debug and because the center of the map itself is updating, and even tried passing null to trigger all fields to no avail.</p> <p>I've checked in debug and the property for the MapOverlay GeoCoordinate always seems to be null. I've tried adding the following to the code-behind which puts the circle where I want it, but I can't seem to get it to happen based on the event...</p> <pre><code>GpsCoordinateConverter converter = new GpsCoordinateConverter(); Map.Layers[0][0].GeoCoordinate = (GeoCoordinate)converter.Convert(((ViewModel.ReportViewModel)DataContext).MapCenter, typeof(GeoCoordinate), null, null); </code></pre> <p>Does anyone know why this would be or how to fix this? I'd prefer not to abandon the MVVM architecture for this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload