2011-08-31 71 views
4

我有一個使用Bing Map控件的WP Phone應用程序。我有一個對象數組,每個對象都有一個位置。我迭代數組以將引腳放置在地圖上(請參見下文)。我有一個綁定到每個引腳的觸摸事件,以允許用戶點擊引腳來開始操作。Windows Phone上的Bing地圖 - 將點擊事件添加到圖釘;顯示更多詳細信息

現在我希望輕鬆地顯示與要在文本框中顯示的針相關的對象的信息。我如何從與點擊/點擊的圖釘對應的數組中檢索對象?

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 
} 

非常感謝提前!

+0

使用pin.Tap事件 – invalidusername

回答

7

senderPushpin,所以你可以簡單地強制轉換它:

var pushpin = sender as Pushpin 

然後你就可以訪問它的內容。如果您需要更詳細的綁定,請使用圖釘的Tag屬性。

此外,如果您使用Windows Phone 7.1(芒果),我建議您使用Pushpin上的Tap事件。而且我還建議您考慮使用數據綁定,而不是手動添加C#中的項目。

+1

類型化圖釘做了訣竅。謝謝。也將更新爲芒果的Tap事件。偶然,你有鏈接到描述圖釘數據綁定的地方嗎? –

+0

我會推薦這篇文章:http://msdn.microsoft.com/en-us/gg266447 –

+0

奇妙 - 謝謝克勞斯! –

相關問題