![](/img/trans.png)
[英]How do I maintain the file order in Windows Explorer when drag and dropping files into wpf/C# application?
[英]How can I allow Drag and Drop from Windows Explorer into a C# WPF application?
我知道在这个问题上有很多答案,但我仍然无法让它工作。 我已经在应用程序的每个级别的每个控件上启用了AllowDrop,并尝试捕获每个控件上的DragEnter和Drop无效。 我可以在应用程序中拖放项目,但是每当我尝试从Windows资源管理器或桌面等中添加内容时,它都会显示“无”图标。 我有什么想法可能做错了吗?
这是我正在做的一个例子。 仍然没有显示移动光标,也不会点击MainWindow_DragEnter函数。
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.AllowDrop = true;
this.DragEnter += new DragEventHandler(MainWindow_DragEnter);
}
void MainWindow_DragEnter(object sender, DragEventArgs e)
{
e.Effects = DragDropEffects.Move;
}
}
}
我相信我解决了我的问题。 我以管理员身份运行Visual Studio。 当它启动我的应用程序时,它无法识别Explorer中的拖动,因为Explorer在用户模式下运行。 希望这个骨头移动可以帮助其他人。
AllowDrop仅激活使用拖放的可能性。 你必须自己处理它。
如您所见,具有AllowDrop的对象也具有事件DragEnter,DragOver,DragLeave。 你必须在这个时刻编写你想要发生的事情。 您可以更改光标,接受丢弃的项目等。但您必须自己动手。 例如,查找DragEventArgs.Effects。
我刚刚打开了一个新的WPF应用程序,选择了窗口,启用了AllowDrop,添加了事件处理程序DragEnter并放入其中:e.Effects = DragDropEffects.Move; 对我来说很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.