1
votes

I'm trying to create a pushpin in a Silverlight Bing Map that is both draggable as well as clickable. I found some code here http://pietschsoft.com/post/2010/05/30/Draggable-Pushpins-using-Bing-Maps-Silverlight-Control.aspx to achieve the draggable part.

I've mapped mouseclick on the map to drop a pin.

However, the problem (and this exists with the default pushpin as well) is that clicking on the pushpin seems to be handled by the map control first so I end up dropping another pin, instead of registering an event on the pushpin.

If I replace the pin with a ControlTemplate that is a button, I can trap the click, but now I don't have a draggable pushpin.

Can anyone recommend a solution ?

1

1 Answers

1
votes

I've found this approach to work. Recording it here so that it helps someone else.

  1. Create a Content Template for the DraggablePushpin from above link so that it only contains a DraggableButton(below).
  2. inherit from Button to create a DraggableButton (referenced in the template above)

  3. In this DraggableButton, override the OnMouseLeftButtonDown and the OnMouseLeftButtonUp and pass them to the DraggablePushpin. I created a property called ThePin on the DraggableButton and set that in the OnApplyTemplate method of the DraggablePushpin. You can call GetTemplateChild() in OnApplyTemplate to get a reference to the DraggableButton instance in the pushpin.

  4. The DraggableButton can now override the Click event for custom actions and also pass through the other events to the DraggablePushpin so that it works as expected.

There maybe a cleaner way to do this, but this is what worked for me.