Windows Phone上的必应地图-添加点击事件到图钉;显示更多细节
本文关键字:事件 显示 细节 Phone 添加 地图 Windows | 更新日期: 2023-09-27 18:07:06
我有一个使用Bing地图控件的WP Phone应用程序。我有一个对象数组,每个对象都有一个位置。我迭代数组以将大头针放置在地图上(见下文)。我有一个触摸事件绑定到每个引脚,允许用户点击引脚开始一个动作。
现在-我想,点击,从对象显示信息,涉及到该引脚显示在一个文本框中。我如何从对应于被点击/点击的图钉的数组中检索对象?
foreach (wikiResult result in arrayResults)
{
double lat = double.Parse(result.Latitude, CultureInfo.InvariantCulture);
double lng = double.Parse(result.Longitude, CultureInfo.InvariantCulture);
statusTextBlock.Text = result.Latitude + " " + result.Longitude + " " + lat + " " + lng;
GeoCoordinate d = new GeoCoordinate(lat, lng);
Pushpin pin;
pin = new Pushpin();
pin.Location = d;
pin.Content = result.Name;
pin.MouseLeftButtonUp += new MouseButtonEventHandler(pin1_MouseLeftButtonUp);
myMap.Children.Add(pin);
}
void pin1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
//display the content from the object in a text box
}
提前感谢!
sender
就是Pushpin
,所以你可以简单地对它进行类型转换:
var pushpin = sender as Pushpin
然后你可以访问它的内容。如果您需要更详细的绑定,请使用Pushpin的Tag
属性。
同样,我建议你在Pushpin
上使用Tap
事件,如果你使用的是Windows Phone 7.1 (Mango)。我还建议您考虑使用数据绑定,而不是手动从c#中添加项。