不允许在VS2010扩展中的WPF ToolWindow中拖放 [英] Drag Drop Within WPF ToolWindow in VS2010 Extension Not Allowed

查看:146
本文介绍了不允许在VS2010扩展中的WPF ToolWindow中拖放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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!

推荐答案

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

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:

在工具窗口(用户控件)中,覆盖OnDragEnterOnDragOver(重要!)和OnDrop.未能覆盖OnDragOver会导致拖放失败.

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

OnDragEnter中,执行以下操作:

  1. 检查是否可以处理投递
  2. 如果是这样,请将DragEventArgs.Handled设置为true并将DragEventArgs.Effects设置为适当的值
  3. 致电base.OnDragEnter()
  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()

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

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!

OnDrop

  1. 处理下落
  2. DragEventArgs.Handled设置为true
  3. 致电base.OnDrop()
  1. Handle the drop
  2. Set DragEventArgs.Handled to true
  3. Call base.OnDrop()

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

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

这篇关于不允许在VS2010扩展中的WPF ToolWindow中拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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