Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I allow Drag and Drop from Windows Explorer into a C# WPF application?

I know there have been tons of answers on this subject, but I still cannot get it to work at all. I've enabled AllowDrop on every control at every level of the application, and tried to catch DragEnter and Drop on every control to no avail. I can drag and drop items inside the application, but any time I try to bring something in from Windows Explorer or the desktop, etc. it gives me the No icon. Any ideas what I might be doing wrong?

Here's an example of what I'm doing. Still does not show the move cursor and won't hit the MainWindow_DragEnter function.

    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;
        }
    }
}
like image 919
Seabass__ Avatar asked May 21 '10 15:05

Seabass__


People also ask

Why is my computer not letting me drag and drop?

Restart the Program You're Using If you notice you can't drag and drop into a specific program, there is a chance the software froze. To quickly fix it, save your work and restart the program. Then, try dragging and dropping again.

How do I enable drag and drop in Windows?

Use the Esc Key and Left Click Locate the file or folder you wish to move by left-clicking on it on your desktop. Hit the “Escape” key on your keyboard once. Release the left-click on your mouse. Drag and drop functionality should now work as normal.

How do I change drag and drop settings?

You can also use any of the keyboard shortcuts below to temporarily change the default drag and drop action for this instance. Press and hold the Ctrl key while you drag and drop to always copy. Press and hold the Shift key while you drag and drop to always move.


1 Answers

I've solved my problem I believe. I was running Visual Studio as Administrator. When it launched my application, it didn't recognize drags from Explorer because Explorer was running in User mode. Hope this bonehead move helps someone else out.

like image 191
Seabass__ Avatar answered Oct 24 '22 07:10

Seabass__