0

I'm trying to fiddle with an idea, and one big concept is dropping programs, bookmarks, etc. I have what I believe to be the gist of it but I'm not receiving any information

private void Border_Drop(object sender, DragEventArgs e)
{            
    FileInfo[] files = (FileInfo[])e.Data.GetData(DataFormats.FileDrop);

    foreach (FileInfo file in files)
    {
        Writer.Text += file.FullName;
    }
}

Though my textblock is never populated? I'd like to get all the properties of File such as FullName, Name, Extension, DirectoryName, etc.

Any pointers on where to go from here? I've been trying to read the MSDN of the event but nothing is coming up, and I've searched stackoverflow and nothing is working for my case scenario.

Dev
  • 1,780
  • 3
  • 18
  • 46
EasyBB
  • 6,176
  • 9
  • 47
  • 77
  • When you say nothing is working. You took code like https://stackoverflow.com/questions/5662509/drag-and-drop-files-into-wpf followed the advice and tried dropping into some sort of panel? Or the code here with a circular usercontrol https://learn.microsoft.com/en-us/dotnet/framework/wpf/advanced/walkthrough-enabling-drag-and-drop-on-a-user-control – Andy Feb 26 '20 at 16:14
  • Does the event handler get called? – Aluan Haddad Feb 26 '20 at 17:15
  • I'm dropping on a border element and getting that information to post in a text block so I can read it – EasyBB Feb 28 '20 at 01:50

2 Answers2

0

One possible reason is that you have attached the event handler to the wrong control. Try attaching the event handler to the Form, or if that does not work, the textblock.

I would also highly recommend doing some debugging. Place a breakpoint in the event handler to see if it is called, and if so, what happens in it.

JonasH
  • 28,608
  • 2
  • 10
  • 23
  • Thanks I'll add break points, I always forget about them being a front end web developer first, then back end, now software – EasyBB Feb 28 '20 at 01:48
0

WPF has two different routed event handling mechanisms: bubbling and tunneling. Bubbling is the "normal" way to do it, and tunneling is when you see all those PreviewThis and PreviewThat in the event name. It's possible, that another control has aready marked the event as handled, and so you don't see it in your event handler.

If you need documentation for WPF drag and drop, read this

If you need some really custom, really low level stuff on this subject, you can also read up on Object Linking and Embedding This is probably how drag-and-drop is implemented in Word so that you can drag images and Excel tables into Word documents and they will display natively. But to use this you will probably need to use some Win32 API calls which is a bit of a bummer.

MatX
  • 108
  • 1
  • 6