Phone.Maps-项目集合必须在使用ItemsSource前空 [英] Phone.Maps- Items collection must be empty before using ItemsSource
问题描述
我有过类似的错误一看,却无法找到一个符合我的方案。
I have had a look through similar errors, but cannot find one matching my scenario.
我现在用的例子在这里: 的http://wp.qmatteoq.com/maps-in-windows-phone-8-and-phone-toolkit-a-winning-team-part-2/
I am using the 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 receive 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.
堆栈跟踪:
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个项目在我这都将作为图钉到列表清单。
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.
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' is a List with variables in it including Geocoordinates.
推荐答案
你设置的ItemsSource的那一刻,项目变为只读。你必须选择你要使用哪一个。你不能混搭在这里。因此,设置的ItemsSource之前,调用Items.Clear()
The moment you set ItemsSource, Items becomes read only. You will have to pick which one you want to use. You can't mix and match here. So before setting ItemsSource, call Items.Clear()
这篇关于Phone.Maps-项目集合必须在使用ItemsSource前空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!