2009-12-20

Hello World for Bing Maps + Silverlight + F#

The Bing Maps Silverlight Control was released in November.  You can get a Bing Maps account and the Silverlight Interactive SDK at http://www.microsoft.com/maps/developers/.  I’ve committed code for this blog that shows you how to get started with it using an F# Silverlight application.  I did not need to write any C# or XAML.  This example application simply displays the default map.

http://2.latest.funslae.appspot.com/

The code can be browsed here or checked out:

svn checkout http://ctaggart.googlecode.com/svn/tags/blog-2009/2009-12-20/funslae/

The F# code is in App.fs.  It simply implements a Silverlight application, create a Grid control and adds a Map control.  The class is in a namespace and not a module, so that Silverlight can find it.  You will need to replace the hard coded ApplicationId with one from your Bing Maps account before you upload it somewhere.  Visual Studio 2010 Beta 2 comes with a “F# Silverlight Library” template.  I used it, then edited the project file (right-click project > “Edit Project File”), to create the F# Silverlight Application.  In the first PropertyGroup of the project file, I set SilverlightApplication to true and added the last five elements so that it creates a manifest and puts everything in a xap. I also added the xcopy command at the end to copy the funslae.xap to be hosted by the server.  On the server side, I simply added a static index.html and made sure the content type for a xap was correct.

F# is a good match for Silverlight.  Hopefully, this helps some people get started exploring the two.