Silverlight 拖放(无画布)

发布于 2024-09-01 06:25:01 字数 265 浏览 6 评论 0原文

我正在尝试将 Silverlight 元素从窗口的一个部分拖放到(滑动)到另一个部分。

我已经在元素上实现了 MouseLeftButtonDown、MouseMove 和 MouseLeftButtonUp 事件处理程序,但遇到了一些问题。

我见过的所有示例都涉及通过设置 Canvas.Left 和 Canvas.Top 属性来移动元素。我试图操纵的所有元素都不存在于画布中。有没有办法根据鼠标的坐标设置被拖动元素的绝对位置?或者是否有一个我错过的针对此问题的预先打包的解决方案?

I'm trying to drag and drop (slide) a Silverlight element from one part of a window to another.

I've implemented the MouseLeftButtonDown, MouseMove, and MouseLeftButtonUp event handlers on the element, but I've run into a bit of a problem.

All of the examples I've seen involve moving the element by setting the Canvas.Left and Canvas.Top properties. None of the elements I'm trying to manipulate live inside a Canvas. Is there a way to set the absolute position of the element being dragged, based on the coordinates of the mouse? Or is there a prepackaged solution to this problems somewhere that I've missed?

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

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

发布评论

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

评论(2

嘴硬脾气大 2024-09-08 06:25:01

除 Canvas 之外的所有面板都使用某种约束来定位其子面板。只有 Canvas 允许您使用绝对定位。这就是为什么我认为这是实现拖放的唯一方法。

请随意在现有面板上使用画布。只需记住从其原始父级中删除拖动的元素并将其放入画布中(或拖动某种副本)并在鼠标向上执行相反的操作即可。

All panels but Canvas use some kind of constraint to position their children. Only Canvas lets you use absolute positioning. That's why I think it is the only way to implement drag and drop .

Feel free to use a Canvas on top of your existing panel. Just remember to remove the dragged element from its original parent and put it in the Canvas (or drag some kind of copy) and do the reverse on mouse up.

蓦然回首 2024-09-08 06:25:01

在任何容器(不仅仅是 Canvas)内实现项目绝对定位的一种方法是使用转换而不是 Left/Top 属性。例如,要设置Left=50 Top=80,您可以通过转换修改边距值。

One way of achieving absolutely positioning an item inside any container, not only Canvas, is to use transformation instead of Left/Top properties. For instance, to set at Left=50 Top=80 you can modify the margin values through transformation.

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