Windows Phone上的Bing Map - 将点击事件添加到图钉;显示更多细节

时间:2011-08-31 20:26:14

标签: c# windows-phone-7 bing-maps bing

我有一个使用Bing Map控件的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
}  

非常感谢提前!

1 个答案:

答案 0 :(得分:7)

senderPushpin,因此您只需对其进行类型转换:

var pushpin = sender as Pushpin

然后你可以访问它的内容。如果需要更详细的绑定,请使用图钉的Tag属性。

此外,如果您使用的是Windows Phone 7.1(Mango),我建议您使用Tap上的Pushpin事件。我还建议您考虑使用数据绑定,而不是手动添加C#中的项目。