i want to implement a Drag/Drop mechanic in WPF, but it didn’t work…
With Windows-Forms it worked, …
First i set AllowDrop to True. In windows-forms you can already drag items into the richtextbox and the cursor changes.
With WPF …. nothing happens.
The nexT point: Implement DragEnter and DragDrop Methodes.
I did it like the online-manuals says. (ok i had to try out something more, because DragDrop doesn’t exists in WPF)
I think all tutorials for drag/drop is only for Windowsforms, nothing for WPF…
Is there a problem with the richtextbox? If i change it to “allowDrop” – nothing happens. The cursor is still a not-allowed-symbol.
Hope someone can help 🙂
Examplecode from tutorials i read:
richTextBox1.AllowDrop = true;
void richTextBox1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.None;
if (e.Data.GetDataPresent(DataFormats.XXX))
{
e.Effect = DragDropEffects.Copy;
}
}
void richTextBox1_DragDrop(object sender, DragEventArgs e)
{
//intert in richtextbox ...
richTextBox1.methodeXY();
}
I was curious as to why so I had a little play and eventually got it to work. Essentially, I started by binding to the PreviewXXX events like so:
Even still, they STILL didn’t work. But the answer came here, in the form of elevated permissions. I usually run VS2010 with admin elevation. Because I was dropping some files from Explorer onto my
RichTextBox, it was essentially banning the operation because Explorer runs in a non-elevated user mode. Running the VS2010 in a non-elevated mode fixed the problem. The article linked does suggest some workarounds, but I haven’t tried them yet.