I have a Map control with a MapsItemControl in it:
<maps:Map x:Name="MyMap"> <maptk:MapExtensions.Children> <maptk:MapItemsControl> <maptk:MapItemsControl.ItemTemplate> <DataTemplate> . . . </DataTemplate> </maptk:MapItemsControl.ItemTemplate> </maptk:MapItemsControl> </maptk:MapExtensions.Children> </maps:Map>
I populate the MapItemsControl in the code as follows:
var itemCollection = MapExtensions.GetChildren((Map)MyMap).OfType<MapItemsControl>().FirstOrDefault(); itemCollection.ItemsSource = myItemCollection;
This works correctly when adding elements to a map for the first time. But if I want to update it with a new soruce item collection, I get the following error in the line itemCollection.ItemsSource = myItemCollection; :
Items must be empty before using Items Source
So, I tried adding a line to my code to remove the elements before setting the source again, without success:
var itemCollection = MapExtensions.GetChildren((Map)MyMap).OfType<MapItemsControl>().FirstOrDefault(); itemCollection.Items.Clear(); itemCollection.ItemsSource = myItemCollection;
Now I get the following exception on the line itemCollection.Items.Clear(); :
Collection is in silent mode
How to update elements in MapItemsControl ?
source share