如何通过点击bing地图中的图钉来获取图钉的模型对象?
我的图钉以如下常见方式添加到地图中:
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
相关的其他信息,例如名称、描述、网址等。我该怎么做?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您应该使用
Tap
事件,而不是MouseLeftButtonUp
。其次,事件处理程序中的
sender
是Pushpin
,它的DataContext
属性是您绑定的PushpinModel
,所以简单地做:First of all, you should use the
Tap
event, instead ofMouseLeftButtonUp
.Secondly, the
sender
in the event handler, is thePushpin
, and it'sDataContext
property is your boundPushpinModel
, so simply do: