Wil*_*ill 4 c# bing bing-maps windows-phone-7
我有一个使用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
}
Run Code Online (Sandbox Code Playgroud)
提前谢谢了!
这sender是Pushpin你可以简单地对它进行类型转换:
var pushpin = sender as Pushpin
Run Code Online (Sandbox Code Playgroud)
然后你可以访问它的内容.如果需要更详细的绑定,请使用Tag图钉的属性.
此外,如果您使用的是Windows Phone 7.1(Mango),我建议您使用该Tap事件Pushpin.我还建议您考虑使用数据绑定,而不是手动添加C#中的项目.
| 归档时间: |
|
| 查看次数: |
4824 次 |
| 最近记录: |