【问题标题】:Bing Map on Windows Phone - add click events to pushpins; display more detailsWindows Phone 上的 Bing 地图 - 将点击事件添加到图钉;显示更多细节
【发布时间】:2011-08-31 20:26:14
【问题描述】:

我有一个使用 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
}  

非常感谢!

【问题讨论】:

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


    【解决方案1】:

    senderPushpin,因此您可以简单地进行类型转换:

    var pushpin = sender as Pushpin
    

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

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

    【讨论】:

    • 对图钉进行类型转换就可以了。谢谢。还将更新到 Mango 的 Tap 事件。您是否偶然有一个链接到某个描述图钉数据绑定的地方?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多