简体   繁体   English

BingMapControl WP7 XAML 数据绑定中心

[英]BingMapControl WP7 XAML Databinding Center

I have the following XAML declared:我声明了以下 XAML :

       <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).绑定工作正常 - 除了 map 没有保持居中(最初它使用 Center 属性上的绑定正确居中)。 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.发生这种情况时,绑定的图钉会适当移动,但最终它会从 map 移开,因为 map 不会自行重新居中。 How can I get the map to re-center itself using data-binding?如何让 map 使用数据绑定重新居中?

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).这意味着我无法直接绑定到我正在映射的记录上的 GeoCoordinate 值(因为如果我通过平移移动 map 中心,我不希望更新该值)。 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.相反,我必须在我的视图 model 中有一个单独的属性来绑定,当用户滚动数据时,我会使用所选记录中所需的 GeoCoordinate 值保持更新。

It is strange that the Center property required two way binding whereas the pushpin worked fine without two binding.奇怪的是,Center 属性需要两种方式绑定,而图钉在没有两种绑定的情况下可以正常工作。

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 视图:

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

I would have liked it to work with data binding.我本来希望它与数据绑定一起工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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