0

I am trying to add a Bing Map WPF control to a Winforms app using the direction here like so:

public FormDataMapper()
{
    InitializeComponent();
    BingMapHostUserControl.Map.CredentialsProvider = new ApplicationIdCredentialsProvider("WinnieThePoohAndEeyoreToo");
}

(my user control is named BingMapHostUserControl). With thsi I get, "'DataMapper.BingMapHostUserControl' does not contain a definition for 'Map'

So I changed the code to this, referencing the elementHost:

public FormDataMapper()
{
    InitializeComponent();
    elementHostBingMap.Map.CredentialsProvider = new ApplicationIdCredentialsProvider("TheWonderfulThingAboutTiggers");
}

...but get a similar err msg with that

'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"

What am I doing wrong?

UPDATE

Here is the XAML for the User Control:

<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>

And, from the Designer.cs file of the main form:

// 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;
4

1 回答 1

1

由于您将地图元素命名为 dataMapper,因此您必须使用该属性名称而不是您所遵循的代码示例中使用的“地图”。尝试这个:

elementHostBingMap.dataMapper.CredentialsProvider = new ApplicationIdCredentialsProvider("TheWonderfulThingAboutTiggers");
于 2015-08-06T16:50:07.820 回答