How to get the model object of a pushpin through a click on the pushpin in bing map?

687 views Asked by At

My pushpins are added to the map in a common way like this:

C#:

private readonly ObservableCollection<PushpinModel> _pushpins = new observableCollection<PushpinModel>();

public ObservableCollection<PushpinModel> Pushpins
{
    get{return _pushpins;}
}

XAML:

<my:MapItemsControl ItemsSource="{Binding Pushpins}">
    <my:MapItemsControl.ItemTemplate>
        <DataTemplate>
            <my:Pushpin Style="{StaticResource PushpinStyle}" 
                        MouseLeftButtonUp="Pushpin_MouseLeftButtonUp" 
                        Location="{Binding Location}" 
                        Content="{Binding Num}">
            </my:Pushpin>
        </DataTemplate>
    </my:MapItemsControl.ItemTemplate>
</my:MapItemsControl>

On clicking a pushpin i can get the Pushpin as sender and get Location information. But i would like to track down to it's PushpinModel object to get other informations associated with the Pushpin, like name, description, urls, etc. How can i do that?

1

There are 1 answers

0
Claus Jørgensen On BEST ANSWER

First of all, you should use the Tap event, instead of MouseLeftButtonUp.

Secondly, the sender in the event handler, is the Pushpin, and it's DataContext property is your bound PushpinModel, so simply do:

var pushpinModel = (sender as Pushpin).DataContext as PushpinModel;