我需要在加载页面上的控件之前从代码背后设置CredentialsProvider。我在代码后面有“ApiKey”依赖项属性,并将其绑定到Bing Maps silverlight Control,但它不起作用。它在运行时出现错误“无效凭据”。设置Bing地图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正在从用户控件继承。
您是否确认ApiKey属性get返回您的有效密钥? – DaveB 2010-08-06 15:58:17
是的,我检查了很多次 – Neutralizer 2010-08-06 18:23:57
我的这个问题太老了。我通过不使用它解决了这个问题。我会标记答案,检查谁在几天内获得最高票数。 – Neutralizer 2011-09-27 17:17:56