[VB2012]我正在使用以下代码反复将数据库中的图钉添加到Bing Maps WPF MapLayer(ml)中:
Dim pp As New Pushpin()
pp.Location = New Location(utm.Latitude.GetDecimalCoordinate, utm.Longitude.GetDecimalCoordinate)
pp.PositionOrigin = PositionOrigin.BottomCenter
pp.Content = PinLabel
pp.ToolTip = PinLabel
pp.FontSize = 6.0R
' need to put an AddHandler in here
ml.Children.Add(pp)
图钉被添加并显示在maplayer上。我不明白的是如何为每个图钉添加AddHandler,以便我可以确定何时单击图钉。我真的很感激一些见解。我只是没有从我找到的在线示例中得到我需要做的事情。
答案 0 :(得分:1)
在WPF中,Addhandler语句与其他VB.Net应用程序中的结构相同。由于所有Pushpins都被路由到此事件,因此发送方对象将为您提供正确的。
Addhandler pp.MouseDown, AddressOf pp_MouseDown
您必须使用与事件匹配的签名制作子例程。
Private Sub pp_MouseDown(sender As Object, e As RoutedEventArgs)
'sender is the PushPin in question
Dim pp as PushPin = DirectCast(sender, PushPin)
End Sub