我查看了类似的错误,但找不到与我的场景匹配的错误。
我正在使用这里的示例: http ://wp.qmatteoq.com/maps-in-windows-phone-8-and-phone-toolkit-a-winning-team-part-2/
经常,但不是每次..我收到以下异常:
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.
堆栈跟踪:
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)
我正在做的是在 Windows Phone 8 中填充地图。当它工作时,它很好。我的列表中有 25 项作为图钉添加到列表中。
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>
C#
ObservableCollection<DependencyObject> children = MapExtensions.GetChildren(map1);
var obj = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;
obj.ItemsSource = details;
'details' 是一个列表,其中包含地理坐标等变量。