【发布时间】:2011-09-28 00:50:34
【问题描述】:
在页面上加载控件之前,我需要从后面的代码中设置 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。
【问题讨论】:
-
您是否确认 ApiKey 属性 get 正在返回您的有效密钥?
-
我的这个问题太老了。我通过不使用它解决了这个问题。我会在几天内标记答案检查谁获得最高票数。
标签: c# silverlight bing-maps