Windows phone 7 遍历现有的可观察集合,收集所述类c中的2个属性#

Windows phone 7 遍历现有的可观察集合,收集所述类c中的2个属性#,windows-phone-7,iteration,observablecollection,Windows Phone 7,Iteration,Observablecollection,目前,im使用名为locationItems的可观察集合来存储locations类中的对象 在我正在处理的页面上,我当前通过上一页的选定索引传递一个对象。 DataContext=App.ViewModel.LocationItems[index] 不过,我希望有一个选项可以遍历该ObservableCollection LocationItems{get;private set;}中的所有项,这样我就可以从其创建的对象中收集值,并将它们绘制在地图上 那么如何迭代这些呢 我想到foreach语句

目前,im使用名为locationItems的可观察集合来存储locations类中的对象

在我正在处理的页面上,我当前通过上一页的选定索引传递一个对象。 DataContext=App.ViewModel.LocationItems[index]

不过,我希望有一个选项可以遍历该ObservableCollection LocationItems{get;private set;}中的所有项,这样我就可以从其创建的对象中收集值,并将它们绘制在地图上


那么如何迭代这些呢

我想到foreach语句,假设您使用的是C#。例如:


我想到了foreach语句,假设您使用的是C#。例如:


这不起作用,首先尝试了:P,我现在通过mapz.ItemsSource=App.ViewModel.LocationItems完成了这项工作,并使用MapItemsControl和DataTemplate在xaml上填充了它。这不起作用,首先尝试了:P,我现在已经通过mapz.ItemsSource=App.ViewModel.LocationItems完成了这项工作,并使用MapItemsControl和datatemplate在xaml上填充了它
foreach (var location in LocationItems) 
{ 
   ... 
}