不允许在 VS2010 扩展中的 WPF 工具窗口内拖放

发布于 2024-08-19 12:11:04 字数 367 浏览 1 评论 0原文

我这里有一个奇怪的问题。我使用带有工具窗口的 Visual Studio 集成包/VSIX 项目向导创建了一个简单的插件。在该窗口中,我想从列表框中进行简单的拖/放操作,然后将其放在同一窗口中。我在普通的 WPF 程序中做了同样的事情,但是当我在 WS 工具窗口中执行此操作时,这是不允许的。我开始拖/放操作(由 PreviewMouseLeftButtonDown 事件启动)并调用 DragDrop.DoDragDrop() 方法,我立即获得停止标志光标。不允许拖拽。

有什么想法吗?我猜是安全限制或这些 WPF 控件托管在 ToolWindowPane 和旧的 Visual Studio IDE COM 内容中这一事实的影响...感谢您的帮助!

I have a strange problem here. I've created a simple plugin using the wizard for a Visual Studio Integration Package / VSIX project with a tool window. Within that window I want to do a simple drag/drop from a listbox and drop within the same window. I've done the same thing in a normal WPF program, but when I do this in a WS toolwindow it's not allowed. I start the drag/drop operation (initiated by a PreviewMouseLeftButtonDown event) and call the DragDrop.DoDragDrop() method, I get the stop-sign-cursor at once. No dragging allowed.

Any ideas? Security restrictions or an effect of the fact that these WPF controls are hosted inside a ToolWindowPane and old Visual Studio IDE COM stuff I guess... Thanks for any help!

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

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

发布评论

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

评论(1

夏の忆 2024-08-26 12:11:04

Microsoft 的 Alin Constantin 在这里帮助了我,甚至还写了一篇关于如何在 VS2010 中正确进行拖放的博客文章!

http://alinconstantin.blogspot。 com/2010/02/drag-and-drop-in-visual-studio-2010.html


突出显示,以防链接失效:

在工具窗口(UserControl)中,覆盖 OnDragEnterOnDragOver重要!)和 OnDrop。未能覆盖 OnDragOver 将导致拖/放失败。

OnDragEnter 中,执行以下操作:

  1. 检查是否可以处理拖放
  2. 如果可以,请将 DragEventArgs.Handled 设置为 trueDragEventArgs.Effects 为适当的值
  3. 调用 base.OnDragEnter()

OnDragOver 中,您必须执行与 相同的操作 >OnDragEnter。如果您未能设置 Handled,Visual Studio 将接管并且您将无法处理放置!

OnDrop 中,

  1. 处理拖放 将
  2. DragEventArgs.Handled 设置为 true
  3. 调用 base.OnDrop()

记住,不是处理OnDragOver 将导致 Visual Studio 接管拖动操作,从而使您无法在 OnDrop 中处理它。

Alin Constantin at Microsoft helped me out here and has even written a blog post on how to do drag/drop within VS2010 properly!

http://alinconstantin.blogspot.com/2010/02/drag-and-drop-in-visual-studio-2010.html


Highlights, in case of link rot:

In your tool window (the UserControl), override OnDragEnter, OnDragOver (important!) and OnDrop. Failure to override OnDragOver will cause drag/drop to fail.

In OnDragEnter, do the following:

  1. Check to see if you can handle the drop
  2. If so, set DragEventArgs.Handled to true and DragEventArgs.Effects to the appropriate value
  3. Call base.OnDragEnter()

In OnDragOver, you must do the same thing as OnDragEnter. If you fail to set Handled, Visual Studio will take over and you won't be able to handle the drop!

In OnDrop,

  1. Handle the drop
  2. Set DragEventArgs.Handled to true
  3. Call base.OnDrop()

Remember, not handling OnDragOver will result in Visual Studio taking over the drag operation, denying you the ability to handle it in OnDrop.

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