Win 8 App: Bing Maps Binding Location

2019-09-01 19:03发布

问题:

I want to bind the Longitude and Latidute value from a Bing Map. But that doesn't work. if I code the values in the xaml it works fine. But with the binding the Map does not center.

Here is my example:

<Maps:Map ZoomLevel="7" x:Name="myMap" Credentials="my_Code">
                    <Maps:Map.Center>
                        <Maps:Location Latitude="{Binding Maps.Latitude}" Longitude="{Binding Maps.Longitude}" />
                    </Maps:Map.Center>
                    <Maps:Map.Children>
                        <Maps:Pushpin>
                            <Maps:MapLayer.Position>
                                <Maps:Location Latitude="{Binding Maps.Latitude}" Longitude="{Binding Maps.Longitude}" />
                            </Maps:MapLayer.Position>
                        </Maps:Pushpin>
                    </Maps:Map.Children>
                </Maps:Map>

The position is marked in the map but the map does not center the marked position. If I do this it works:

<Maps:Map ZoomLevel="7" x:Name="myMap" Credentials="my_Code">
                    <Maps:Map.Center>
                        <Maps:Location Latitude="25" Longitude="25" />
                    </Maps:Map.Center>
                    <Maps:Map.Children>
                        <Maps:Pushpin>
                            <Maps:MapLayer.Position>
                                <Maps:Location Latitude="{Binding Maps.Latitude}" Longitude="{Binding Maps.Longitude}" />
                            </Maps:MapLayer.Position>
                        </Maps:Pushpin>
                    </Maps:Map.Children>
                </Maps:Map>

回答1:

According to the documentation here: http://msdn.microsoft.com/en-us/library/hh846504.aspx

The Center property of the map dos not support data binding. I believe this was done on purpose as the center property changes frequently when the map moves and data binding can cause a lot of performance issues.