I'm trying to add multiple pushpins from a list to Bing Maps on Windows Phone. The name of each pushpin needs to be different, because I want to be able to remove them individually later using MainMap.Children.Remove(SpecificPushpin);
.
This is my 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);
}
Of course, I receive an error after the first loop through the foreach on the MainMap.Children.Add(pushpin);
line, because "pushpin" is already an existing name.
I also tried using this:
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) });
But then I will never be able to romove the pushpins individualy.
Does anyone know how I can give a variable name to each pushpin in my list, or knows another way to fix my problem?
pushpin
object inside the foreach loop. – Ashok Damaniif (AppSettings.Contains("cbxAttractionChecked")) { MainMap.Children.Remove(pushpin); }
It gets in that if when the user unchecks a checkbox. This doesn't work though. – user3478148