Search code examples
c#.netbing-mapsitemscontrolwindows-phone

clearing a mapItemsControl.Itemtemplate WP7 Maps


hi im recurringly updating this map and i noticed its acumulating items rather than just refreshing all items for example

Im assing items to it by mapz.ItemsSource = App.ViewModel.LocationItems; how do i clear the existing items in mapz before this ?

  <my:Map x:Name="myMap" Height="480" Width="444" CredentialsProvider="NON YE BIZ" 
                        Grid.ColumnSpan="1" LogoVisibility="Collapsed" CopyrightVisibility="Collapsed" Margin="5,0,10,0" VerticalContentAlignment="Top" HorizontalContentAlignment="Left" >
                    <my:MapItemsControl x:Name="mapz" ItemsSource="{Binding LocationItems}" Width="450">
                        <my:MapItemsControl.ItemTemplate>
                            <DataTemplate>
                                <my:Pushpin Name="MyPushPin" Location="{Binding Target_Coordinate}" Content="{Binding Target_NickName}"/>
                    </DataTemplate>
                </my:MapItemsControl.ItemTemplate>
                </my:MapItemsControl>
                </my:Map>

Solution

  • Simply call LocationItems.Clear(). If LocationItems is a ObservableCollection, the map with clear off the already rendered items.

    No reason at all to access the UI directly when using data bindings.