我试图从列表中添加多个图钉到Windows Phone上的Bing地图。每个图钉的名称需要不同,因为我希望能够在以后使用MainMap.Children.Remove(SpecificPushpin);
单独删除它们。Bing Maps列表中的项目添加新图钉
这是我的foreach:
Pushpin pushpin = new Pushpin();
Attractions attractions = new Attractions();
foreach (var attraction in Attractions.allAttractions)
{
pushpin.GeoCoordinate = new GeoCoordinate(attraction.Latitude, attraction.Longtitude);
pushpin.Content = attraction.Title;
pushpin.Background = new SolidColorBrush(Colors.Blue);
pushpin.Foreground = new SolidColorBrush(Colors.White);
MainMap.Children.Add(pushpin);
}
当然,我收到一个错误通过对MainMap.Children.Add(pushpin);
行的foreach第一循环之后,因为“图钉”已经是现有名称。
我也是用这个尝试:
MainMap.Children.Add(new Pushpin() { Content = attraction.Title, GeoCoordinate = new GeoCoordinate(attraction.Latitude, attraction.Longtitude), Background = new SolidColorBrush(Colors.Yellow), Foreground = new SolidColorBrush(Colors.Black) });
但后来我将永远无法individualy移去那些所谓的图钉。
有谁知道我可以给我的列表中的每个图钉一个变量名,或知道另一种方法来解决我的问题?
化妆'pushpin' foreach循环内部对象。 –
通过这样做,我仍然无法删除某些图钉,对吧?我试过这样做:'if(AppSettings.Contains(“cbxAttractionChecked”)) { MainMap.Children.Remove(pushpin); }' 如果用户取消选中某个复选框,就会发生这种情况。这虽然不起作用。 – user3478148