1

我的图钉以如下常见方式添加到地图中:

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>

单击图钉时,我可以将图钉作为发件人并获取位置信息。但我想追踪它的PushpinModel对象以获取与 相关的其他信息Pushpin,如名称、描述、url 等。我该怎么做?

4

1 回答 1

3

首先,您应该使用Tap事件,而不是MouseLeftButtonUp.

其次,sender事件处理程序中的 是Pushpin,它的DataContext属性是你的 bound PushpinModel,所以只需这样做:

var pushpinModel = (sender as Pushpin).DataContext as PushpinModel;
于 2012-01-25T13:41:41.270 回答