我正在尝试使用方向here向Bingforms应用添加Bing Map WPF控件,如下所示:
public FormDataMapper()
{
InitializeComponent();
BingMapHostUserControl.Map.CredentialsProvider = new ApplicationIdCredentialsProvider("WinnieThePoohAndEeyoreToo");
}
(我的用户控件名为BingMapHostUserControl)。我得到了,"' DataMapper.BingMapHostUserControl'不包含' Map'
的定义所以我将代码改为此,引用了elementHost:
public FormDataMapper()
{
InitializeComponent();
elementHostBingMap.Map.CredentialsProvider = new ApplicationIdCredentialsProvider("TheWonderfulThingAboutTiggers");
}
...但是用
获得类似的错误消息'System.Windows.Forms.Integration.ElementHost' does not contain a definition for 'Map' and no extension method 'Map' accepting a first argument of type 'System.Windows.Forms.Integration.ElementHost' could be found"
我做错了什么?
以下是用户控件的XAML:
<UserControl x:Class="DataMapper.BingMapHostUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF">
<Grid>
<m:Map x:Name="dataMapper" ></m:Map>
</Grid>
</UserControl>
并且,从主窗体的Designer.cs文件:
// elementHostBingMap
//
this.elementHostBingMap.Dock = System.Windows.Forms.DockStyle.Fill;
this.elementHostBingMap.Location = new System.Drawing.Point(0, 0);
this.elementHostBingMap.Name = "elementHostBingMap";
this.elementHostBingMap.Size = new System.Drawing.Size(764, 481);
this.elementHostBingMap.TabIndex = 1;
this.elementHostBingMap.ChildChanged += new System.EventHandler<System.Windows.Forms.Integration.ChildChangedEventArgs>(this.elementHost2_ChildChanged);
this.elementHostBingMap.Child = this.bingMapHostUserControl1;
答案 0 :(得分:1)
由于您将地图元素命名为dataMapper,因此您必须使用该属性名称而不是“Map”,这是您所遵循的代码示例中使用的内容。试试这个:
elementHostBingMap.dataMapper.CredentialsProvider = new ApplicationIdCredentialsProvider("TheWonderfulThingAboutTiggers");