我使用下面的代码来显示XML文件中的多个图钉。我想知道如何为每个要传递值的图钉设置点击事件
foreach (var root in Transitresults)
{
var accentBrush = (Brush)Application.Current.Resources["PhoneAccentBrush"];
var pin = new Pushpin
{
Location = new GeoCoordinate
{
Latitude = root.Lat,
Longitude = root.Lon
},
Background = accentBrush,
Content = root.Name
};
BusStopLayer.AddChild(pin, pin.Location);
}
}发布于 2011-09-23 16:36:59
你所拥有的非常接近,试试这个:
foreach (var root in Transitresults)
{
var accentBrush = (Brush)Application.Current.Resources["PhoneAccentBrush"];
var pin = new Pushpin
{
Location = new GeoCoordinate
{
Latitude = root.Lat,
Longitude = root.Lon
},
Background = accentBrush,
Content = root.Name,
Tag = root
};
pin.MouseLeftButtonUp += BusStop_MouseLeftButtonUp;
BusStopLayer.AddChild(pin, pin.Location);
}
}
void BusStop_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
var root = ((FrameworkElement)sender).Tag as BusStop;
if (root != null)
{
// You now have the original object from which the pushpin was created to derive your
// required response.
}
}发布于 2011-09-23 16:43:27
在PushPin事件的MSDN page中,您可以看到Tap事件可用,因此您可以注册一个处理程序:
pin.Tap += args => { /* do what you want to do */ };https://stackoverflow.com/questions/7526211
复制相似问题