Todd Thompson
Todd Thompson

Reputation: 40

AddHandler for pushpins in Bing Maps

[VB2012] I am repeatedly adding pushpins from a database to a Bing Maps WPF MapLayer (ml) using the following code:

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)

The pushpins are added and displayed on the maplayer. What I don't understand is how to add the AddHandler for each pushpin so that I can determine when a pushpin is clicked. I would really appreciate some insight. I'm just not getting what I need to do from the online examples I have found.

Upvotes: 1

Views: 840

Answers (1)

OneFineDay
OneFineDay

Reputation: 9024

In WPF the Addhandler statement is the same construction as in other VB.Net applications. Since all Pushpins are routed to this event, the sender object will get you the right one.

Addhandler pp.MouseDown, AddressOf pp_MouseDown

You have to make the sub routine with the signature that matches the event.

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

Upvotes: 1

Related Questions