如何绑定在必应地图Silverlight的最大和最小缩放级别缩放、绑定、大和、最小

2023-09-03 20:49:14 作者:流浪往生

我想实现一个自定义缩放滑块在我的Silverlight应用程序Bing地图的控制。我可以设置它的机制在pretty的直接方式:

I would like to implement a custom zoom slider for a Bing Maps control in my silverlight application. I can set up the mechanics of it in a pretty straightforward way:

<Slider ... Value="{Binding ZoomLevel, Mode=TwoWay, ElementName=MyMap}"/>

不过,我不能找到一种方法,结合最大和滑块的最大和最小的可用缩放级别的地图上最小的属性。我使用的是默认视图(公路,航空),并没有自定义tilesets的或任何幻想。

However, I can't find a way to bind the Maximum and Minimum properties of the Slider to the maximum and minimum available zoomlevel for the map. I am using the default views (Road, Aerial) and no custom tilesets or anything fancy.

我想是这样的:

Maximum="{Binding Path=Map.Mode.ZoomRange.To, Mode=TwoWay}"
Minimum="{Binding Path=Map.Mode.ZoomRange.From, Mode=TwoWay}"

但是,这并不正常工作。当我的地图负载,最小值被设置为0.0,并且最大值被设定为1.0。 Map.Mode.ZoomRange的实际值分别为1.0和17.0(为特定位置,我看现在的最大不同的地方在地图的中心是不同的)。

But that doesn't work. When my map loads, the Minimum value is set to 0.0, and the Maximum value is set to 1.0. The actual values of Map.Mode.ZoomRange are 1.0 and 17.0 (for the particular location I am looking at now. The Max changes depending on where the map is centered).

我如何绑定这些属性,我的新的自定义滑块?

How can I bind these properties to my new custom slider?

推荐答案

您将无法绑定喜欢这一点,因为模式不是依赖项属性也不是 MapMode 的依赖对象。无论是任何的其他属性链也不它们实施 INotifyPropertyChanged的。所以结合这些是pretty的多注定了。

You won't be able to bind like this because Mode is not a dependency property nor is MapMode a dependency object. Neither are any of the other properties in the chain nor do they implement INotifyPropertyChanged. So binding these is pretty much doomed.

您将需要一些code。这可能是在范围改变地图的 ModeChanged 事件触发,在这种情况下,你可以在点更新的最小值/最大值。

You will need some code. It might be that the Map's ModeChanged event fires when the range is changed, in which case you can update the the Min/Max at the point.

如果做不到这一点使用看法的一个变化事件,如 TargetViewChanged ViewChangeEnd

Failing that use one of the view changed events like TargetViewChanged or ViewChangeEnd.