silverlight 4 应用程序中未获取 DragEnter/Over、Drop 事件

发布于 2024-09-09 03:05:17 字数 539 浏览 5 评论 0原文

我将 UserControl 对象从一个 Canvas 拖到另一个 Canvas 上,目的是放到那里。当鼠标悬停在目标上时,拖动的对象实际上位于目标下方。我没有收到 DragEnter、DragOver 或 DragLeave 事件。如果我将对象放在那里,我不会收到 Drop 事件。

我的根对象是一个边框,然后是一个网格。网格覆盖整个浏览器客户端区域。它有 8 列。每列中都有一个由 XAML 放置的画布。

奇怪行为的示例:当我将项目从第 3 列拖动到第 4 列(或任何更大列)时,对象会在画布下方滑动。如果我从第 3 列拖动到第 2 列(或任何较小的列),则对象会滑过顶部。因此,zorder 似乎受到画布创建顺序的影响。有人可以澄清这一点吗?

每列中的 Canvas 对象都具有关联的 DragEnter/Leave 事件,但无论对象移至 Canvas 上方还是下方,都不会触发这些事件。

我发现Canvas必须有背景才能获取鼠标事件。列中的每个画布都有一个背景。如果我没有拖动任何东西,鼠标事件就会触发。

我已经快束手无策了,希望得到一些帮助。

谢谢, 格雷格

I'm dragging UserControl objects from one Canvas to another with the intention of dropping there. When mousing over the destination, the dragged object actually goes under it. I get no DragEnter, DragOver or DragLeave events. If I drop the object there, I get no Drop event.

My root object is a border, then a grid. The grid covers the entire browser client area. It has 8 columns. In each of the columns there is a canvas that is placed by the XAML.

Example of odd behavior: When I drag an item from column 3 to column 4 (or any greater) the object slides under the canvas. If I drag from column 3 to column 2 (or any lesser) the object slides over the top. So it appears that zorder is affected by the order of creation of the Canvases. Can someone clarify this?

The Canvas objects in each of the columns have DragEnter/Leave events associated but none of them fire, whether the object goes over or under the Canvas.

I found that a Canvas must have a background in order to get mouse events. Each of the Canvases in the columns have a Background. The mouse events fire if I'm not dragging anything.

I'm nearing the end of my rope and sure would appreciate some assistance.

Thanks,
Greg

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

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

发布评论

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

评论(1

乖乖 2024-09-16 03:05:17

@toxoplasmotic:是的。

RE:没有触发任何事件。
事实证明,Drag 事件已连接,但不提供任何功能。

RE:在各种放置目标画布下方/上方拖动。
画布创作的“自然秩序”似乎建立了某种秩序。

但这些并不是真正的重点。

解决方案#1。
Silverlight 3 引入了新的表达式混合行为:MouseDragElementBehavior。它封装了相当多的拖放功能。它被保留在 SL4 中。

解决方案#2。
在 codeplex 上有一个 Silverlight 工具包,它(在实验阶段)有另一个非常好的拖/放功能封装。如果您不使用列表框和树视图等,则这似乎可能需要一些额外的编码。

解决方案#3。
但最重要的是:使用 Alex Van Beek 记录良好的代码进行拖放操作非常容易。它在这里:http://blogs.infosupport.com/blogs/alexb/a​​rchive/2009/09/07/A-complete-Silverlight-3-drag-and-drop-solution.aspx

成功的关键是将拖动的对象与其父对象分离,并将其与浏览器窗口的抽象(通常是根对象或另一个透明的画布)相关联。困难(不是那么困难)是保持各个坐标系同步。 (“从”画布,“到”画布,拖动的对象)

干杯!
格雷格

@toxoplasmotic: yes.

RE: Getting no events firing.
As it turns out, the Drag events are wired up, but provide no functionality.

RE: Dragging under/over the various drop target canvases.
There seems to be some kind of zorder that's established by the 'natural order' of the creation of the canvases.

But these things aren't really the important points.

Solution #1.
With Silverlight 3, there was introduced a new Expression Blend Behavior: MouseDragElementBehavior. It encapsulates quite a bit of drag/drop functionality. It is preserved in SL4.

Solution #2.
On codeplex there is a Silverlight Toolkit that has (in the experimental stages) another very nice encapsulation of drag/drop functionality. It appears that this one might require a little extra coding if you're not working with list boxes and tree views, etc.

Solution #3.
But the capper is this: it's pretty easy to do drag/drop using Alex Van Beek's fairly well documented code. It is here: http://blogs.infosupport.com/blogs/alexb/archive/2009/09/07/A-complete-Silverlight-3-drag-and-drop-solution.aspx

The key to success is to disassociate the dragged object from its parent and associate it with an abstraction of the browser window, usually the root object or another canvas that's transparent. The difficulty (not so difficult) is to keep the various coordinate systems in sync. (the "from" canvas, "to" canvas, dragged object)

Cheers!
Greg

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