最近私はBingマップコントロールの使用を開始しましたが、同じ問題を抱えています。エレガントではありませんが、必要なときに手動でMap
コントロールを作成することで回避できました。
私の場合、地図は私のアプリケーションの主な焦点ですので、ほとんど即座にロードする必要があります。アプリケーション自体が完全にレンダリングされるように(ユーザーが何が起こっているかを知るため)、コンテンツがMainWindow
にレンダリングされるまで、Map
コントロールの作成を延期します。あなたが好きなもの使ってこれを実現することができます
あなたのシナリオでは
XAML
<Grid x:Name="MapPanel">
<!-- Placeholder text while the map is loading -->
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="Loading map..." />
</Grid>
コードビハインド
protected override void OnContentRendered(EventArgs e)
{
base.OnContentRendered(e);
// Change the cursor to a waiting cursor so the user knows we are loading something
var previousCursor = Cursor;
Cursor = Cursors.Wait;
// Load the application Id credentials required for the Bing map
var provider = new ApplicationIdCredentialsProvider(Properties.Resources.BingMapsAPIKey);
// Set up the Bing map control
var map = new Map();
map.Mode = new AerialMode(labels: true);
map.CredentialsProvider = provider;
map.HorizontalAlignment = HorizontalAlignment.Stretch;
map.VerticalAlignment = VerticalAlignment.Stretch;
// Render the map control over the top of the loading text in the map panel
MapPanel.Children.Add(map);
// Reset the application cursor
Cursor = previousCursor;
}
を、あなたは必ずしもロードする必要はありませんこの時点でMap
コントロール代わりに、コントロールが遅延ロードされ、マップが必要なときにホストコントロールに本質的に通知し、まだロードされていなければそのポイントでロードすることができます。
希望に役立ちます。