Note that there are some explanatory texts on larger screens.

plurals
  1. POPhone.Maps- Items collection must be empty before using ItemsSource
    text
    copied!<p>I have had a look through similar errors, but cannot find one matching my scenario.</p> <p>I am using the example from here: <a href="http://wp.qmatteoq.com/maps-in-windows-phone-8-and-phone-toolkit-a-winning-team-part-2/" rel="nofollow">http://wp.qmatteoq.com/maps-in-windows-phone-8-and-phone-toolkit-a-winning-team-part-2/</a></p> <p>Quite often, but not every time.. I receive the following exception:</p> <pre><code>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. </code></pre> <p>Stacktrace:</p> <pre><code> 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&amp; 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) </code></pre> <p>What I am doing is populating a Map in Windows Phone 8. When it works, it is fine. I have 25 items in my list which are added as pushpins to the list.</p> <p>XAML:</p> <pre><code>&lt;my:Map Height="696" MouseLeftButtonDown="Close_popup" HorizontalAlignment="Left" Name="map1" VerticalAlignment="Top" Width="480" Grid.RowSpan="2" ZoomLevel="5.5" &gt; &lt;toolkit:MapExtensions.Children&gt; &lt;toolkit:UserLocationMarker x:Name="UserLocationMarker" Visibility="Visible" /&gt; &lt;toolkit:MapItemsControl &gt; &lt;toolkit:MapItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;toolkit:Pushpin MouseLeftButtonUp="pin_click" GeoCoordinate="{Binding Location1}" Template="{StaticResource PushpinControlTemplate1}"/&gt; &lt;/DataTemplate&gt; &lt;/toolkit:MapItemsControl.ItemTemplate&gt; &lt;/toolkit:MapItemsControl&gt; &lt;/toolkit:MapExtensions.Children&gt; &lt;/my:Map&gt; </code></pre> <p>C#</p> <pre><code> ObservableCollection&lt;DependencyObject&gt; children = MapExtensions.GetChildren(map1); var obj = children.FirstOrDefault(x =&gt; x.GetType() == typeof(MapItemsControl)) as MapItemsControl; obj.ItemsSource = details; </code></pre> <p>'details' is a List with variables in it including Geocoordinates.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload