silverlight bing 地图中可拖动和可点击的图钉

发布于 2024-11-02 02:21:36 字数 482 浏览 2 评论 0原文

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

我已经在地图上映射了鼠标单击以放置图钉。

然而,问题(默认图钉也存在这个问题)是,单击图钉似乎首先由地图控件处理,因此我最终放弃了另一个图钉,而不是在图钉上注册事件。

如果我用作为按钮的 ControlTemplate 替换图钉,我可以捕捉点击,但现在我没有可拖动的图钉。

有人可以推荐一个解决方案吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惜醉颜 2024-11-09 02:21:36

我发现这种方法很有效。记录在这里,希望能帮助到其他人。

  1. 从上面的链接为 DraggablePushpin 创建一个内容模板,以便它只包含一个 DraggableButton(如下)。
  2. 继承Button来创建一个DraggableButton(在上面的模板中引用)

  3. 在这个DraggableButton中,重写OnMouseLeftButtonDown和OnMouseLeftButtonUp并传递将它们添加到 DraggablePushpin 中。我在 DraggableButton 上创建了一个名为 ThePin 的属性,并在 DraggablePushpin 的 OnApplyTemplate 方法中对其进行了设置。您可以在 OnApplyTemplate 中调用 GetTemplateChild() 来获取对图钉中的 DraggableButton 实例的引用。

  4. DraggableButton 现在可以重写自定义操作的 Click 事件,并将其他事件传递给 DraggablePushpin,以便其按预期工作。

也许有一种更干净的方法可以做到这一点,但这对我有用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文