0

次のように、次の方向を使用して、Bing Map WPF コントロールを Winforms アプリに追加しようとしています

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

1 に答える 1

1

マップ要素に dataMapper という名前を付けたため、次のコード サンプルで使用されていた "Map" の代わりにそのプロパティ名を使用する必要があります。これを試して:

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