Draggable AND clickable pushpin in silverlight bing map

情到浓时终转凉″ 提交于 2019-12-24 06:43:09

问题


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:


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.



来源:https://stackoverflow.com/questions/5712470/draggable-and-clickable-pushpin-in-silverlight-bing-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!