在Bing Maps WPF上居中和缩放 [英] Center and Zoom on 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."/>
然后在要更改它们的位置设置Center
和ZoomLevel
属性.例如:
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
事件处理程序中设置Center
和ZoomLevel
.
If that doesn't work, you might need to set Center
and ZoomLevel
in the Loaded
event handler.
这篇关于在Bing Maps WPF上居中和缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!