Welcome to MSDN Blogs Sign in | Join | Help

Data Binding with the Virtual Earth Control

I was very excited to hear that the Virtual Earth (VE) team was creating a Silverlight control and that they announced at Mix a CTP (Community Technology Preview).  I promptly downloaded it and started playing with it.  From the Circus Mashimus contest I entered, I had learned about the Best Buy Remix APIs that let me search for products, stores, and product availability at stores using a simple REST API.  The Stores API actually returns Longitude/Latitude coordinates.

When I started looking at the VE control, it was apparent that the control was missing some features related to data binding:  I wanted to bind the coordinates returned from the Stores Service to shapes in the Map Layer, use a data templates to define what each store shape would look like, and synchronize the selection of stores in a listbox to the center of the map.

Take a look here to see the app.

It turns out that because of the power of XAML and Silverlight’s .NET framework, I can add my own attached properties to any dependency object using Custom Attached Properties.  This let me do binding and use templates just like a ListBox or DataGrid.  So to create an example like the one in the picture where I want a BestBuy logo placed whereever there is a Best Buy Store, I want to use a Data Template like this:

<DataTemplate x:Key="BestBuyShape">
    <Image Stretch="None" 
        ToolTipService.ToolTip="{Binding Name}"
        Source="{Binding Logo, Source={StaticResource StoresDS}}" 
        m:MapLayer.MapPosition="{Binding Converter={StaticResource StoreToLocationConverter}}"
        m:MapLayer.MapPositionMethod="BottomLeft"/>
</DataTemplate>

and then that template is used with a data source here:

<m:Map Grid.Row="1" Margin="4" Grid.Column="1" Mode="AerialWithLabels" x:Name="Map" 
ve:Properties.CenterPoint="{Binding SelectedStore, Source={StaticResource ViewModel}, Converter={StaticResource StoreToLocationConverter}}"> <m:Map.Children> <m:MapLayer x:Name="BestBuyLocations" ve:Properties.ItemsSource="{Binding Items, Source={StaticResource StoresDS}}" ve:Properties.ItemTemplate="{StaticResource BestBuyShape}"/> </m:Map.Children> </m:Map>

I’ve shared the source code for these useful properties on the MSDN Code Gallery so you can use them too.  Tell me what you think and what you use them for.  I will be releasing a Best Buy kit for Silverlight soon so you can the very cool service as well.  image

5/24/2009 - MSS - Updated URL to Stores Service Documentation.

Published Sunday, March 22, 2009 5:14 PM by Michael S. Scherotter

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Data Binding with the Virtual Earth Control

Michael, this is great! The team here at Best Buy Remix really wants to thank you for all of the energy you are putting into developing on the API. I am watching the blog for all the cool things you are building. This is what it's all about!

Thanks again.

Keith Burtis (Best Buy Remix)

Sunday, March 22, 2009 9:04 PM by keith burtis

# re: Data Binding with the Virtual Earth Control

Michael, this is great! The team here at Best Buy Remix really wants to thank you for all of the energy you are putting into developing on the API. I am watching the blog for all the cool things you are building. This is what it's all about!

Thanks again.

Keith Burtis (Best Buy Remix)

Sunday, March 22, 2009 9:05 PM by keith burtis

# Virtual Earth Developer Resources

Virtual Earth Developer Resources

Thursday, March 26, 2009 9:24 PM by Chris Pietschmann

# My Artist Explorer Wins at the Circus Mashimus Mashup Contest!

I just heard that my entry into the Circus Mashimus contest was just selected as Best In Show winner.&#160;

Thursday, April 09, 2009 8:19 PM by Synergist

# My Artist Explorer Wins at the Circus Mashimus Mashup Contest!

I just heard that my entry into the Circus Mashimus contest was just selected as Best In Show winner

Friday, April 10, 2009 12:03 AM by Community Blogs

# re: Data Binding with the Virtual Earth Control

Very nice, could you publish the entire solution to be run in Visual Studio. Also the stores api seems dead http://remix.bestbuy.com/docs/Types/Stores, even though the demo runs.

Thanks,

Jim

Friday, May 08, 2009 11:00 PM by Jim Gordon

# re: Data Binding with the Virtual Earth Control

fyi the docs for stores have moved here: http://remix.bestbuy.com/documentation/Stores_API

Friday, May 22, 2009 6:17 PM by Steve

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker