在Bing Maps WPF上居中和缩放 [英] Center and Zoom on Bing Maps WPF

查看:95
本文介绍了在Bing Maps WPF上居中和缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Bing Maps WPF对话框,并希望通过编程设置中心和缩放级别.我尝试使用SetValue(),但是我没有找到正确的属性来传递给它.

I created a Bing Maps WPF dialog box and would like set the center and zoom level programmatically. I have tried using SetValue(), but I haven't found the right property to pass to it.

这是我的必应地图"对话框的XAML:

Here is the XAML for my Bing Maps dialog:

<Window 
        x:Class="RAPMkI.BingMapsDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
        Title="BingMapsDialog" Height="378" Width="467">
    <Grid>
        <m:Map CredentialsProvider="Haha, nice try."/>
        <Button Content="Locate" Margin="0,0,0,0" Name="button1" HorizontalAlignment="Right" Width="Auto" Height="Auto" VerticalAlignment="Top" />
    </Grid>
</Window>

后面的代码如下:

namespace RAPMkI
{
    /// <summary>
    /// Interaction logic for BingMapsDialog.xaml
    /// </summary>
    public partial class BingMapsDialog : Window
    {
        public BingMapsDialog(Location center, int zoom)
        {
            InitializeComponent();
        }
    }
}

是否有一种方法可以在初始化时使用我已经通过的Location和缩放来设置对话框的中心和缩放级别?

Is there a way to set the center and zoom level of my dialog box upon initialization, using the Location and zoom that I have passed it?

推荐答案

您首先需要给地图起一个名称,以便您可以通过编程方式对其进行访问.例如:

You first need to give your map a name so you can access it programmatically. e.g.:

<m:Map Name="theMap" CredentialsProvider="Haha, nice try."/>

然后在要更改它们的位置设置CenterZoomLevel属性.例如:

Then set the Center and ZoomLevel properties where you'd like them changed. For example:

public BingMapsDialog(Location center, int zoom)
{
    InitializeComponent();
    theMap.Center = center;
    theMap.ZoomLevel = zoom;
}

如果这不起作用,则可能需要在Loaded事件处理程序中设置CenterZoomLevel.

If that doesn't work, you might need to set Center and ZoomLevel in the Loaded event handler.

这篇关于在Bing Maps WPF上居中和缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆