This project has moved and is read-only. For the latest updates, please go here.


Apr 4, 2013 at 10:20 AM
I'm using ItemTemplate instead of ItemContainerStyle in the MapItemsControl but MapItems in my observableCollection don't move when I pan the map - but they do locate to the correct location when their Location property changes. I think this is something to do with the DataTemplate i'm using..
Apr 4, 2013 at 4:48 PM
I can't imagine how you would set the MapPanel.Location property of a MapItem without a Style. Anyway, there isn't much to say without having seen your DataTemplate...
Apr 5, 2013 at 1:16 PM
Edited Apr 5, 2013 at 1:17 PM
Here is an example using your MainPage.xaml page... I slowed the clock down to 1 second and pan the map. Make the changes below by inserting the datatemplate and the modified MapItemsControl .. firstly, none of the originally items display, but watch the moving pin, it only relocates on Location changed. In noticed you're using data template with the PolyLine and it works just fine - just the MapItem doesn't behave right with a DataTemplate.

Here is what i did.. I added this ..
        <map:MapItemsControl ItemsSource="{StaticResource Points}"
                             ItemTemplate="{StaticResource PinTemplate}"
instead of this
        <map:MapItemsControl ItemsSource="{StaticResource Points}"
                             ItemContainerStyle="{StaticResource PointItemStyle}"
And I added this DataTemplate, everything from Canvas down is the same as your PointItemStyle
    <!-- DataTemplate for moving pins -->
    <DataTemplate x:Key="PinTemplate">
        <map:MapItem map:MapPanel.Location="{Binding Location}" HorizontalAlignment="Left" VerticalAlignment="Bottom" >
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal"/>
                        <VisualState x:Name="Disabled"/>
                        <VisualState x:Name="MouseOver">
                                <DoubleAnimation Storyboard.TargetName="labelBackground" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.1"/>
                    <VisualStateGroup x:Name="SelectionStates">
                        <VisualState x:Name="Unselected"/>
                        <VisualState x:Name="Selected">
                                <DoubleAnimation Storyboard.TargetName="selectedPath" Storyboard.TargetProperty="Opacity" To="0.7" Duration="0:0:0.1"/>
                <Path Name="selectedPath" Fill="White" Opacity="0">
                        <EllipseGeometry RadiusX="15" RadiusY="15"/>
                <Path Name="path" Fill="Transparent" Stroke="Gray" StrokeThickness="2">
                        <EllipseGeometry RadiusX="8" RadiusY="8"/>
                <Grid Canvas.Left="15" Canvas.Top="-8">
                    <Rectangle Name="labelBackground" Fill="White" Opacity="0.7"/>
                    <TextBlock Margin="2,0,2,0" Text="{Binding Name}"/>
Apr 5, 2013 at 4:26 PM
The problem is that you have a MapItem in a DataTemplate for a MapItem. This result is two nested MapItems, where the MapPanel.Location property is set on the "inner" one, but not on the "outer" one.

MapPanel.Location is only effective on elements that are direct children of a MapPanel. This is true for the MapItems in a MapItemsControl, as the MapItemsControl's ItemPanel template uses a MapPanel. But the MapItem in your DataTremplate does not have a MapPanel parent, hence setting MapPanel.Location has no effect.

The solution is to stick with ItemContainerStyle. You can't set MapPanel.Location by means of a MapItem's DataTemplate.
Apr 8, 2013 at 3:48 PM
Many thanks... I have done as you recommend and its all working now.