C #: drag and drop in WPF (Richtextbox)

I want to implement a drag / drop mechanism in WPF, but it does not work ... It worked with Windows-Forms, ...

First I set AllowDrop to True. In form windows, you can already drag and drop elements into the richtextbox, and the cursor changes.

With WPF .... nothing happens.

NexT point: do DragEnter and DragDrop Methodes. I did this as the online manuals say. (OK, I had to try something else, because DragDrop does not exist in WPF) I think all the tutorials for drag / drop are only for Windowsforms, nothing for WPF ...

Is there a problem with richtextbox? If I change it to "allowDrop" nothing will happen. The cursor is still an invalid character.

Hope someone can help :)

Sample code from the 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();
}
+3
1

, . , PreviewXXX :

AllowDrop="True" PreviewDragEnter="RichTextBox_DragEnter" PreviewDragOver="RichTextBox_DragEnter" PreviewDrop="RichTextBox_Drop"

. , . VS2010 . Explorer RichTextBox, , Explorer . VS2010 . , .

+7

Source: https://habr.com/ru/post/1779768/


All Articles