简体   繁体   中英

BingMapControl WP7 XAML Databinding Center

I have the following XAML declared:

       <controls:PivotItem Header="map">
            <my:Map x:Name="map"
                    CredentialsProvider="Hidden"
                    Mode="Road"
                    Center="{Binding AppState.MapCenter}"
                    ZoomLevel="15">
                <my:Pushpin Location="{Binding AppState.MapCenter}" />                        
            </my:Map>
        </controls:PivotItem>

The binding works fine - except that the map does not stay centered (initially it centers correctly using the binding on the Center property). The application allows the user to move through a series of records with differing GeoCoordinates. As this happens the bound Pushpin moves appropriately, however eventually it moves off the map because the map does not re-center itself. How can I get the map to re-center itself using data-binding?

I found a second and better resolution that enables databinding. I set the binding mode for the Center to TwoWay:

Center="{Binding MapCenter, Mode=TwoWay}"

This meant I could not bind directly to the GeoCoordinate value on the record that I was mapping (because I did not want that value to be updated if I moved the map center by panning). Instead I had to have a separate property in my view model to bind to which I kept updated with the required GeoCoordinate value from the selected record as the user scrolled through data.

It is strange that the Center property required two way binding whereas the pushpin worked fine without two binding.

At this stage the only resolution that I have found is to set the map view in code each time the mapped point changes as follows:

map.SetView(ViewModelLocator.AppStateStatic.MapCenter, 15);

I would have liked it to work with data binding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM