Skip to content

An example which shows how to use WPF Bing Maps Control in a Windows Forms application.

Notifications You must be signed in to change notification settings

r-aghaei/WinFormsWpfBingMaps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPF Bing Maps Control in Windows Forms

This example shows how you can use WPF Bing Maps Control in a Windows Forms application, enable animation and set the initial view of the map. To do so, follow these instructions:

  1. Create a Windows Forms Application.

  2. Install Microsoft.Maps.MapControl.WPF NuGet package.

  3. Add a new WPF UserControl to your project:

    Right-click on project → choose Add New Item → Add a new User Control (WPF) (It's located under WPF category)

  4. Add the Map to your WPF user control. Basically you need to add the map assembly to the control by adding the following attribute to your user control:

    xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
    

    And adding the map element to the control:

    <Grid>
      <m:Map/>
    </Grid>
    

    Here is the full code for your user control. (Make sure you use the correct namespace):

    <UserControl x:Class="YOURNAMESPACE.UserControl1"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF">
       <Grid>
           <m:Map CredentialsProvider="YOUR MAP KEY" x:Name="myMap" />
       </Grid>
    </UserControl >
    

    • Note: You need a Bing Maps key. If you don't have a Bing maps account, create a Bing Maps account and then get a Bing Maps key from it. For test purpose, you can ignore the map key.

  5. Build your project.

  6. Drop an instance of ElementHost control on your form. You can find it under the WPF Interoperability group in toolbox.

  7. From the smart action panel (at top right of the ElementHost control), set the hosted content to UserControl1 and dock it to the parent container.

  8. Handle the Load event of the Form and use the following code:

     private void Form1_Load(object sender, EventArgs e)
     {
         this.userControl11.myMap.AnimationLevel = AnimationLevel.Full;
         this.userControl11.myMap.Loaded += MyMap_Loaded;
     }
     private void MyMap_Loaded(object sender, System.Windows.RoutedEventArgs e)
     {
         var location = new Location(47.604, -122.329);
         this.userControl11.myMap.SetView(location, 12);
     }
    

    Make sure you use using Microsoft.Maps.MapControl.WPF;.

  9. Run your application.

There you go, The map will appear in your Windows Forms Application and the map zooms in Seattle as center location:

WPF Bing Maps in Windows Forms

More information:

You may want to take a look at the following links for more information:

About

An example which shows how to use WPF Bing Maps Control in a Windows Forms application.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages