从背后的代码设置Bing Maps Silverlight控件属性

问题描述:

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

I need to set the CredentialsProvider from code behind prior to load the control on page. I have "ApiKey" dependency property in code behind and binding it to Bing Maps silverlight Control but it doesn't work. It gives an error "invalid credentials" at run time.

隐藏代码

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继承的.

The class name is MainPage and is being inherited from UserControl.

CredentialsProvider = new ApplicationIdCredentialsProvider("AbcdEfghIjklMNnoP_4rlMTclX8iXiNYUYQnG3GPYoxABCDEmoj3cCBemAAG")