我在 bing 地图上有多个动态图钉。我想在这些图钉上添加鼠标点击事件。告诉我我该怎么做。我正在使用 C# 和 XML 在 Windows 商店应用程序中工作。
问问题
1258 次
1 回答
1
当您以编程方式添加图钉时,将公共事件处理程序添加Tapped
到每个图钉。当图钉被点击时,它将被调用,并且sender
您可以从对象中区分每个图钉并做任何您喜欢的事情。
//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
}
于 2013-04-09T17:20:31.137 回答