ページにコントロールをロードする前に、コード ビハインドから CredentialsProvider を設定する必要があります。コード ビハインドに "ApiKey" 依存関係プロパティがあり、それを Bing Maps Silverlight コントロールにバインドしていますが、機能しません。実行時に「無効な資格情報」というエラーが発生します。
コードビハインド
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 から継承されています。