MapOverlay binding not working

后端 未结 2 1275
不思量自难忘°
不思量自难忘° 2021-01-06 12:16

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 Vie

相关标签:
2条回答
  • 2021-01-06 12:52

    That's a limitation of the Silverlight XAML Parser. Objects initialized as part of XAML elements' properties will not participate in the same logical tree and as such don't have datacontext drilling down into them.

    In order to databind the new Nokia Map control, use MapExtensions from the new Windows Phone Toolkit. For example here's how to create a PushPin in a specific GeoCoordinate using MapExtensions.

    <maps:Map x:Name="Map" Grid.Row="1" Hold="OnMapHold">
        <maptk:MapExtensions.Children>
            <maptk:Pushpin x:Name="RouteDirectionsPushPin" Visibility="Collapsed"/>
            <maptk:MapItemsControl Name="StoresMapItemsControl">
                <maptk:MapItemsControl.ItemTemplate>
                    <DataTemplate>
                        <maptk:Pushpin GeoCoordinate="{Binding GeoCoordinate}" Visibility="{Binding Visibility}" Content="{Binding Address}"/>
                    </DataTemplate>
                </maptk:MapItemsControl.ItemTemplate>
            </maptk:MapItemsControl>
            <maptk:UserLocationMarker x:Name="UserLocationMarker" Visibility="Collapsed"/>
        </maptk:MapExtensions.Children>
    </maps:Map>
    
    0 讨论(0)
  • 2021-01-06 12:56

    To fix this you need to implicitly tell your binding where to find the property, in MVVM Light world it would look like:

        <maps:MapOverlay GeoCoordinate="{Binding Main.CurrentLocation, Source={StaticResource Locator}}">
                                <Ellipse Fill="Blue" Height="20" Width="20" Opacity="50" />
                            </maps:MapOverlay>
    

    also, you will need the dispatcher on the viewmodel to handle the ui change

    0 讨论(0)
提交回复
热议问题