Reputation: 358
I have a multiple dynamic push pins on bing map. I want to add a mouse click event on these push pin. Tell me how can i do it. I am working in windows store app using C# and XML.
Upvotes: 1
Views: 1321
Reputation: 15296
When you are adding pushpins programmatically, add common event handler Tapped
to each pushpin. When pushpin is tapped it will be called and from sender
object you can differentiate each push pin and do whatever you like.
//Suppose I have PushpinsCollection which is list of MyPushpin class. PushpinsCollection is generated dynamically
public class MyPushpin
{
public int PinID { get; set; }
public Pushpin Pin { get; set; }
public Location PinLocation { get; set; }
}
//run foreach loop do add event hanlder and add to map
//Here MyMap is Bing Map control
foreach(var pushpin in PushpinsCollection)
{
var _pin = pushpin.Pin;
_pin.Tapped += Pushpin_Tapped
MapLayer.SetPosition(_pin, PinLocation);
MyMap.Children.Add(_pin);
}
private void Pushpin_Tapped(object sender, TappedRoutedEventArgs e)
{
var TappedPin = (Pushpin)sender;
//TODO: do whatever opetraion you want to with TappedPin
}
Upvotes: 1