MapItemsControls not updating Silverlight Bing Map
Posted
by Matt
on Stack Overflow
See other posts from Stack Overflow
or by Matt
Published on 2010-03-11T05:34:19Z
Indexed on
2010/03/11
5:36 UTC
Read the original article
Hit count: 732
I'm using a MapItemsControl to control my Pushpin items within my Bing silverlight map.
Right on the page load, I add a new pin programatically, and the pin shows up on the map. However I've now taken it further and I'm adding pins to my datasource via a click on the map.
The new pins add to my datasource, but do not show up on the map. Do I need to rebind my datasource to my map control or somehow refresh the datasource? Here's some code
<UserControl.Resources>
<DataTemplate x:Key="PinData">
<m:Pushpin Location="{Binding Location}" PositionOrigin="BottomCenter" Width="Auto" Height="Auto" Cursor="Hand">
<m:Pushpin.Template>
<ControlTemplate>
<Grid>
<myTestApp:MasterPin DataContext="{Binding}"/>
</Grid>
</ControlTemplate>
</m:Pushpin.Template>
</m:Pushpin>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<m:Map x:Name="myMap" CredentialsProvider="" Mode="Road" ScaleVisibility="Collapsed" >
<m:MapItemsControl x:Name="mapItems" ItemTemplate="{StaticResource PinData}"/>
</m:Map>
</Grid>
public partial class Map : UserControl
{
private List< BasePin > dataSource = new List< BasePin >();
public Map()
{
InitializeComponent();
_Initialize();
}
private void _Initialize()
{
//this part works and adds a pin to the map
dataSource.Add( new BaseSite( -33.881532, 18.440208 ) );
myMap.MouseClick += Map_MouseClick;
mapItems.ItemsSource = dataSource;
}
public void Map_MouseClick(object sender, MapMouseEventArgs e))
{
BasePin pin = new BasePin();
pin.Location = myMap.ViewportPointToLocation( e.ViewportPoint );
dataSource.Add( pin );
}
}
© Stack Overflow or respective owner