Search Wiki:
Data Binding Properties for XAML-only data binding with the Virtual Earth Map Control for Silverlight.

These are Custom Attached Properties for the Virtual Earth control for Silverlight Community Technology Preview (CTP) that enable common data binding scenarios of binidng a MapLayer shapes to a collection, using a data template, and binding the centerpoint of the map to data as well.
  • ve:Properties.ItemsSource MapLayer Items Source
  • ve:Properties.ItemTemplate MapLayer Item Template
  • ve:Properties.CenterPoint Map Center Point that supports data binding

Using the Properties

  1. Add the Properties.cs file to the Silverlight project
  2. Add the namespace xmlns:ve="clr-namespace:Synergist.VE to the UserControl where the VE Map is placed
  3. Use the ve:Properties.CenterPoint on a VE Map
  4. User the ve:Properties.ItemsSource and ve:Properties.ItemTemplate on a VE MapLayer

Usage Example

This is the XAML for http://xmldocs.net/bestbuy that demonstrates all three of the custom attached properties.

vebestbuy.png
<UserControl x:Class="TestBestBuySilverlightKit.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:local="clr-namespace:TestBestBuySilverlightKit"
    xmlns:ve="clr-namespace:Synergist.VE"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    d:DesignWidth="640" d:DesignHeight="480" 
    xmlns:BestBuy="clr-namespace:BestBuy;assembly=BestBuySilverlightKit" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" 
    xmlns:m="clr-namespace:Microsoft.VirtualEarth.MapControl;assembly=Microsoft.VirtualEarth.MapControl">
    <UserControl.Resources>
        <BestBuy:Stores x:Key="StoresDS" d:IsDataSource="True"/>
        <local:ViewModel x:Key="ViewModel" d:IsDataSource="True"/>
        <local:StoreToLocationConverter x:Key="StoreToLocationConverter"/>
        <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>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
 
    	<Grid.ColumnDefinitions>
    		<ColumnDefinition Width="Auto"/>
    		<ColumnDefinition/>
    	</Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal" Grid.Column="1" Margin="4">
            <TextBlock Text="Stores: "/>
            <TextBlock Text="{Binding Items.Count, Source={StaticResource StoresDS}}"/>
            <HyperlinkButton Margin="4" NavigateUri="http://blogs.msdn.com/synerigst" TargetName="_blank" Content="Created by Michael S. Scherotter"/>
            <HyperlinkButton Margin="4" NavigateUri="http://archive.msdn.microsoft.com/VESLBindingProps" Content="Data Binding Source Code" 
                             TargetName="_blank"/>
        </StackPanel>
    	<ListBox Margin="4" Grid.RowSpan="2" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" 
                    ItemsSource="{Binding Mode=OneWay, Path=Items, Source={StaticResource StoresDS}}" 
                    DisplayMemberPath="Name" 
                    MinWidth="100" 
                    SelectedItem="{Binding SelectedStore, Source={StaticResource ViewModel}, Mode=TwoWay}" 
                    ScrollViewer.VerticalScrollBarVisibility="Visible" />
 
    	<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>
    </Grid>
</UserControl>
Last edited Mar 23 2009 at 12:38 AM  by mscherotter, version 11
Updating...
Page view tracker