Why am I getting "does not contain a definition for 'Map'" here?

2.2k views Asked by At

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

There are 1 answers

0
rbrundritt On BEST ANSWER

Since you named the map element dataMapper you will have to use that property name instead of "Map" which is what was used in the code sample you were following. Try this:

elementHostBingMap.dataMapper.CredentialsProvider = new ApplicationIdCredentialsProvider("TheWonderfulThingAboutTiggers");