RichTextBox change text on drag or drop

312 views Asked by At

I was trying to add newline when drading text from one richtextbox to another. I have the text in the draggedText, but it seems that nothing is happening. No newline appears. Every dragge text into the RichTextBox should be in new line. Xaml:

<RichTextBox x:Name="first" PreviewDragEnter="DragEnter_Executed">

C#

 private void DragEnter_Executed ( object sender, DragEventsArgs e )
{
var draggedText = Environment.NewLine + e.Data.GetData( DataFormats.Text ).ToString();
e.Data.SetData ( draggedText ); 
}
1

There are 1 answers

0
Noctis On

Well, a couple of things.

First, the DragEnter is for exactly then ..when the drag enters the area ... usually you'll change the mouse icon, and maybe show a preview of what dropping will do if you'll drop it.

The real magic happens on the Drop event, which is the one actually in charge of doing changes because you dropped the object into the target area.

You'll probably want to append the text to the other textbox (are sure you just want to replace it?), and continue on with whatever you need to do.

You can have a look at the official MSDN page for more