1
votes

[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.

1
If you type in Addhandler pp. are there any events that pop up in intellisense for that object? Is it this object on this site - msdn.microsoft.com/en-us/library/gg427615.aspx? - OneFineDay
That is the right class except that we nees the WPF version. There is nothing for AddHandler pp, but pp has a built in AddHandler. pp.AddHandler(routedEvent as System.RoutedEvent, handler as System.Delgate). I'm confused by this routedevent. How do I implement this? - Todd Thompson
In WPF the Addhandler statement is the same construction as in other VB.Net applications. Addhandler pp.Click, AddressOf pp_click. You have to make the sub routine with the signature that matches the event. - OneFineDay
Thanks DonA. Click is not part of the PushPin, but MouseLeftButtonDown is. After I put in the AddHandler statement, VS stubbed in the sub for it. - Todd Thompson
OK, so how do I mark the question answered. - Todd Thompson

1 Answers

1
votes

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