Windows Phone 上的 Bing 地图 - 将点击事件添加到图钉;显示更多详细信息
我有一个使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
sender
是Pushpin
,因此您可以简单地对其进行类型转换:然后您就可以访问它的内容。如果您需要更详细的绑定,请使用图钉的
Tag
属性。另外,如果您使用的是 Windows Phone 7.1 (Mango),我建议您使用
Pushpin
上的Tap
事件。我还建议您考虑使用数据绑定,而不是从 C# 手动添加项目。The
sender
is thePushpin
so you can simply typecast it: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 thePushpin
, 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#.