在加载页面上的控件之前,我需要从后面的代码中设置 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 继承的。