Silverlight Bing地图中的可拖动和可单击图钉 [英] Draggable AND clickable pushpin in silverlight bing map

查看:87
本文介绍了Silverlight Bing地图中的可拖动和可单击图钉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Silverlight Bing地图中创建一个可拖动和可点击的图钉。我在这里 http://中找到了一些代码: //pietschsoft.com/post/2010/05/30/Draggable-Pushpins-using-Bing-Maps-Silverlight-Control.aspx 来实现可拖动部分。

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.

我已经将mouseclick映射到地图上以放置大头针。

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.

如果我将图钉替换为作为按钮的ControlTemplate,我可以捕获单击,但是现在我没有可拖动的图钉。

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 ?

推荐答案

我发现这种方法有效。

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


  1. 从上方链接为DraggablePushpin创建内容模板,使其仅包含一个DraggableButton(下面)。

  2. 从Button继承以创建DraggableButton(在上面的模板中引用)

  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)

在此DraggableButton中,覆盖OnMouseLeftButtonDown和OnMouseLeftButtonUp并将它们传递给DraggablePushpin。我在DraggableButton上创建了一个名为ThePin的属性,并在DraggablePushpin的OnApplyTemplate方法中进行设置。您可以在OnApplyTemplate中调用GetTemplateChild()以获得对图钉中DraggableButton实例的引用。

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.

DraggableButton现在可以覆盖Click事件以进行自定义操作,还将其他事件传递给DraggablePushpin,以使其按预期工作。

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.

这篇关于Silverlight Bing地图中的可拖动和可单击图钉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆