Pregunta

I'm trying to add a map to my app. The map needs to show customized pins (from png images) And each of them needs somehow to contain a ID that I will use to retrieve data from a database.

So basically when the user taps on them, on the related event, I need to be able to retrieve that ID...

I've been trying two options:


First one is the one described on Microsoft website: http://msdn.microsoft.com/en-us/windowsphonetrainingcourse_usingbingmapslab_topic3.aspx

That works creating customized pins....but I can't find a way to store any data in them that I will be able to retrieve later on. Cause when I create a pin I work on a PushpinModel, but when the click event happens on one of them the sender is not the PushpinModel anymore, but just a Pushpin.


Second one is the one described on many websites and tutorials, that basically suggests to create a Pushpin with transparent background and a picture as content or foreground. (e.g. http://www.geekchamp.com/articles/windows-phone-drawing-custom-pushpins-on-the-map-control-what-options-do-we-have)

With that one I can surely store the ID and retreive it on sender var when the pushpin is tapped.....but the picture completely stands on a wrong position on the map, since it doesn't actually start from the location point but appears only on "content" rectangle of the transparent pushpin.

So, to recap: 1st option: customized pin shows on the right spot, but I can't retrieve the ID. 2nd option: I can retrieve the ID, but the customized pin doesn't show on the right spot.

Any idea on how to solve one of the 2 problems? Or.....do you have any third option?

¿Fue útil?

Solución

You can retrive the PushpinModel from the pushpin. If you followed the tutorial you linked, you've created the pushpin by binding a list of PushpinModel to the MapItemsControl. In that case, the PushpinModel is stored in the DataContext property of the pushpin. To retrieve it from the click event of the pushpin, first cast the sender parameter, then the DataContext property:

var pushpin = (Pushpin)sender;
var model = (PushpinModel)pushpin.DataContext;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top