Is it possible to have a WPF window/element detect the drag'n'dropping of a file from windows explorer in C# .Net 3.5? I've found solutions for WinForms, but none for WPF.
A:
Donnelle
2008-12-02 02:43:48
Thanks for the link, but I already tried that one
NoizWaves
2008-12-02 02:57:07
Didn't have more time to summarise but thought it might get you started. Glad to see you got it sorted.
Donnelle
2008-12-02 17:52:26
+1
A:
Turns out I couldn't drop onto my TextBox for some reason, but dropping onto buttons works fine. Got it working by adding 'AllowDrop="True"' to my window and adding drop event handler to button consisting of:
private void btnFindType_Drop(object sender, DragEventArgs e)
{
if (e.Data is System.Windows.DataObject &&
((System.Windows.DataObject)e.Data).ContainsFileDropList())
{
foreach (string filePath in ((System.Windows.DataObject)e.Data).GetFileDropList())
{
// Processing here
}
}
}
NoizWaves
2008-12-02 03:02:18
+2
A:
Unfortunately, TextBox, RichTextBox, and FlowDocument viewers always mark drag-and-drop events as handled, which prevents them from bubbling up to your handlers. You can restore drag-and-drop events being intercepted by these controls by force-handling the drag-and-drop events (use UIElement.AddHandler and set handledEventsToo to true) and setting e.Handled to false in your handler.
Ed Ball
2008-12-03 05:14:57
Cheers! Your idea is also discussed here: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/a539c487-1dec-4935-b91b-c3ec252eb834
NoizWaves
2008-12-03 11:26:56
+1
A:
Hi,
I noticed that drag&drop in WPF is not as easy as it could be. So I wrote a short article about this topic: http://www.wpftutorial.net/DragAndDrop.html