wpf 应用程序中 bing 地图的凭据无效

Invalid Credentials for bing maps in wpf application

无法显示地图。我仍然收到一条错误消息: "Invalid Credentials. Sign up for a developer account at: http://www.microsoft.com/maps/developers"

但是,我正确地创建了一个帐户并获得了一个有效的密钥:

我的xaml代码:

<Window x:Class="Geography.MainWindow"
        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="MainWindow" Height="350" Width="525">
    <Grid>
        <m:Map CredentialsProvider="*My key*">
        </m:Map>
    </Grid>
</Window>

试试这个代码

<Window x:Class="Geography.MainWindow"
    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="Maps" Height="350" Width="525" Style="{StaticResource OfficeStyle}">
    <Grid>
    <m:Map CredentialsProvider="/*YOUR ID*/" x:Name="myMap" />
    </Grid>
</Window>

然后添加到cs代码中

   using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Text;
   using System.Threading.Tasks;
   using System.Windows;
   using System.Windows.Controls;
   using System.Windows.Data;
   using System.Windows.Documents;
   using System.Windows.Input;
   using System.Windows.Media;
   using System.Windows.Media.Imaging;
   using System.Windows.Shapes;
   using Microsoft.Maps.MapControl.WPF;
   namespace Geography
   {
         /// <summary>
         /// Interaction logic for Maps.xaml
         /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
               InitializeComponent();
               myMap.Focus();
               //Set map to Aerial mode with labels
               myMap.Mode = new AerialMode();
            }
        }
    }

关注 link 了解更多详情:https://msdn.microsoft.com/en-us/library/hh830433.aspx

是我忽略存在的代理

因此,我在 app.config 文件中设置了以下配置,错误消息不再出现:

<system.net>
  <defaultProxy enabled="true" useDefaultCredentials="true">
    <proxy bypassonlocal="True" proxyaddress="http://ProxyAddress:Port"/>
  </defaultProxy>
</system.net>