Windows Phone 上的 Bing 地图 - 将点击事件添加到图钉;显示更多详细信息

发布于 2024-12-02 21:13:58 字数 909 浏览 1 评论 0原文

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

非常感谢!

I have a WP Phone app using a Bing Map control. I have an array of objects, and each object has a location. I iterate the array to place the pins on the map (see below). I have a touch event bound to each pin to allow the user to tap the pin to start an action.

Now - I would like, on tap, to show information from the object that relates to that pin to be shown in a textbox. How can I retrieve the object from the array that corresponds to the pushpin that was tapped/clicked?

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
}  

Many thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小红帽 2024-12-09 21:13:58

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

var pushpin = sender as Pushpin

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

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

The sender is the Pushpin so you can simply typecast it:

var pushpin = sender as Pushpin

And then you can access it's content. If you need more detailed binding, use the Tag property of the Pushpin.

Also, I would suggest you use the Tap event on the Pushpin, if you're using Windows Phone 7.1 (Mango). And I would also recommend that you consider using databindings, instead of manually adding the items from C#.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文