I looked at similar errors, but I can not find one that matches my scenario.
I use an example from here: http://wp.qmatteoq.com/maps-in-windows-phone-8-and-phone-toolkit-a-winning-team-part-2/
Quite often, but not every time .. I get the following exception:
An exception of type 'System.InvalidOperationException' occurred in Microsoft.Phone.Controls.Toolkit.DLL but was not handled in user code Items collection must be empty before using ItemsSource.
Stacktrace:
at Microsoft.Phone.Maps.Toolkit.MapItemsControl.OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue) at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation) at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet) at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) at Microsoft.Phone.Maps.Toolkit.MapItemsControl.set_ItemsSource(IEnumerable value) at NextBuses.MainPage.GetMembersCompleted(Object sender, GetMembersCompletedEventArgs e) at NextBuses.SQLService.Service1Client.OnGetMembersCompleted(Object state)
What I'm doing is filling out the card in Windows Phone 8. When it works, everything is fine. I have 25 items in my list that are added to the contact list.
XAML:
<my:Map Height="696" MouseLeftButtonDown="Close_popup" HorizontalAlignment="Left" Name="map1" VerticalAlignment="Top" Width="480" Grid.RowSpan="2" ZoomLevel="5.5" > <toolkit:MapExtensions.Children> <toolkit:UserLocationMarker x:Name="UserLocationMarker" Visibility="Visible" /> <toolkit:MapItemsControl > <toolkit:MapItemsControl.ItemTemplate> <DataTemplate> <toolkit:Pushpin MouseLeftButtonUp="pin_click" GeoCoordinate="{Binding Location1}" Template="{StaticResource PushpinControlTemplate1}"/> </DataTemplate> </toolkit:MapItemsControl.ItemTemplate> </toolkit:MapItemsControl> </toolkit:MapExtensions.Children> </my:Map>
WITH#
ObservableCollection<DependencyObject> children = MapExtensions.GetChildren(map1); var obj = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl; obj.ItemsSource = details;
'details' is a list with variables in it, including geo-coordinates.
source share