开发者

Bing Map on Windows Phone - add click events to pushpins; display more details

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 a开发者_C百科dvance!


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#.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜