0

在加载页面上的控件之前,我需要从后面的代码中设置 CredentialsProvider。我在后面的代码中有“ApiKey”依赖属性并将其绑定到 Bing Maps silverlight Control,但它不起作用。它在运行时给出错误“无效的凭据”。

代码背后

public static readonly DependencyProperty ApiKeyProperty = DependencyProperty.Register("ApiKey", typeof(string), typeof(MainPage), new PropertyMetadata(""));
protected string ApiKey
{
    get { return this.GetValue(ApiKeyProperty) as string; }
    set { this.SetValue(ApiKeyProperty, value); }
}

XAML

<m:Map x:Name="map" Grid.Row="1" Grid.ColumnSpan="5" Margin="0" CredentialsProvider="{Binding ElementName=silverlightMap, Path=ApiKey}" 
               Mode="Road" MouseMove="map_MouseMove" MouseLeftButtonUp="map_MouseLeftButtonUp" MouseLeftButtonDown="map_MouseLeftButtonDown"
               ViewChangeEnd="map_ViewChangeEnd"></m:Map>

类名是 MainPage,是从 UserControl 继承的。

4

3 回答 3

6
CredentialsProvider = new ApplicationIdCredentialsProvider("AbcdEfghIjklMNnoP_4rlMTclX8iXiNYUYQnG3GPYoxABCDEmoj3cCBemAAG")
于 2011-05-29T20:13:47.463 回答
0

The CredentialsProvider property isn't of type string and doesn't automatically convert strings to a CredentialsProvider instance (how would it choose which sub-class to convert to?)

You'd be best off exposing a CredentialsProvider instance from your code. That way you can return either an API key or client token, perhaps based on your configuration file.

于 2010-08-06T20:44:36.653 回答
0

经过一番努力,我终于发现当 Thread.CurrentUICulture 设置为不变文化时会发生这种情况。确保在 App.Startup 事件处理程序中将其设置为特定的文化(也考虑设置 Thread.CurrentCulture),例如

System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");

当然,您仍然需要使用您的 AppID 正确设置凭据。HTH。

于 2011-05-31T19:46:46.723 回答