UPDATE: I have written a newer version of this article to specifically target the latest Bing Maps Silverlight Control Version 1.0 Release.
You can find the new article here: Getting Started with Bing Maps Silverlight Control v1.0
It seems like forever since MIX’08 when a demo was shown of a new Silverlight-based Virtual Earth Map Control. Well, now FINALLY we actually have a version of the control to “play” around with. The reason I say “play” is because it’s still a CTP (Community Technology Preview). If you read the license file you’ll see that basically the most important points of Microsoft’s position on CTP’s are: 1) You can NOT use it in a production environment, and 2) It’s a Preview, so anything can change from now until the next release (CTP, Beta, whatever). Well, anyway…
I introduce you to the Virtual Earth Silverlight Map Control SDK CTP!
Before I dig into what’s needed to begin development, and show you how simple it is to use; here’s a few highlights of what’s so Awesome about the control.
Why is the Virtual Earth Silverlight Map Control so Awesome?!?
Here’s a few reason:
- **Silverlight!** – Silverlight itself is truly a high point with this new control. You can now Plot/Overlay Rich Media Content (Images, Video, and any Silverlight/XAML content you can think of!) over the Map!
- **Virtual Earth!** – And, last but not least, we can not forget that part of the Vast Awesomeness of this control is just due to the fact that it’s Virtual Earth Mapping!!
What’s Needed to Get Started?
Note: At the time of posting this (3/20/2009 6:26PM CST) the CTP Download is currently down. You can still go to the Microsoft Connect website and Register, then you’ll be able to download the bits when they’re back up. The download issue has been fixed.
Secondly, you’ll need a couple Tools installed first:
- Visual Studio 2008 SP1 **–or-** Visual Web Developer 2008 Express with SP1
- Silverlight Tools for Visual Studio 2008 SP1
Of course you’ll also need to at least be familiar with the basics of Silverlight development. I’m referring to XAML for the most part, so if your familiar with WPF that should be enough to get you started.
For those Virtual Earth developers new to Silverlight; If you need help getting started with learning the basics of Silverlight development, here are some resources that will help:
- Get Started Building Silverlight Applications at http://silverlight.net
- Silverlight Learning Resources at http://silverlight.net
Let’s Display a Map in Silverlight
Create a New Silverlight Application Project
- Run Visual Studio 2008 and create a New Project using the **Silverlight Application** template.
- In the “Add Silverlight Application” dialog box, select the “**Add a new ASP.NET Web project to the solution to host Silverlight**” option and click “OK”. You must select this option to create an ASP.NET Web Application Project or ASP.NET Website because the URL Access Restrictions in Silverlight require the page that hosts the Map control to be hosted using HTTP in order to load/access the Virtual Earth Map Tiles.
Add a Reference to Microsoft.VirtualEarth.MapControl.dll
- Go to the “**Solution Explorer**” and Right-Click “**References**” in the Silverlight Project (not the ASP.NET Web Application Project), and Select “**Add Reference…**”
- Within the “Add Reference” Dialog, Select the “**Browse**” tab and navigate to the folder where the SDK is installed, and select the “**Microsoft.VirtualEarth.MapControl.dll**”. *Note: By Default the SDK is installed in this folder “C:\Program Files (x86)\Microsoft Virtual Earth Silverlight Map Control\CTP\Libraries” *
Display a Virtual Earth Map
- Add a Namespace declaration to to Page.xaml for the Microsoft.VirtualEarth.MapControl namespace.
To do this add the following to the
tag: *xmlns:m="clr-namespace:Microsoft.VirtualEarth.MapControl;assembly=Microsoft.VirtualEarth.MapControl" *</li>
- Add the Map Control to Page by adding the following tag within the Grid in the Page: **</ol> The resulting Page.xaml will look like this:
Change/Set Map Properties Declaratively using XAML and Programatically using C#You can change/set the Map Control’s properties Declaratively using XAML and Programatically using C# (or any other .NET language). Below are examples using XAML and C#. **XAML:** You can change the Map Mode declaratively using XAML by just setting the “Mode” property. For Example, setting it to “Aerial” will change the Map Mode to AerialMapMode.
Next Tutorial/Article: Basics of Adding Polygons and Polylines using XAML and Code