This is a migrated thread and some comments may be shown as answers.

Any samples (XAML and code behind) of how to drag & drop?

2 Answers 50 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Rob Ainscough
Top achievements
Rank 1
Rob Ainscough asked on 02 Mar 2012, 04:40 PM
I'm having NO luck getting drag and drop operations to work with my RadRichTextBox ... can't find any online samples either.

Any hints on how I can make this work?

Thanks, Rob.

2 Answers, 1 is accepted

Sort by
0
TMatt
Top achievements
Rank 2
answered on 04 Mar 2012, 05:17 PM
I see that the online Demo can do this.
But problem with online Demos are that the Code is incomplete. Too many references are inside the Telerik.Example class.
Its hard to see what functions used.I also interested in a step by step xample which shows us how to implement drag and drop images into Editor.

In best way from PC and Macintosh.

Thanks Jens


PS: Ok i got it. But it would be helpfull to see a XAMLflix about it. I think for me it only works in OUT of Browser Mode.
0
Iva Toteva
Telerik team
answered on 05 Mar 2012, 06:04 PM
Hello Rob, Jens,

You can enable dropping files on the editor by setting the property of RadRichTextBox AllowDrop="True".
Then, handle the Drop event and provide your implementation there.
For example, in the online demo (as Jens has mentioned), if you drop an image file, it will be inserted as an InlineImage using the code:

private void editor_Drop(object sender, DragEventArgs e)
{
    FileInfo[] droppedFiles = e.Data.GetData(DataFormats.FileDrop) as FileInfo[];
 
    foreach (FileInfo droppedFile in droppedFiles)
    {
        if (this.IsSupportedImageFormat(droppedFile.Extension))
        {
            using (Stream imageStream = droppedFile.OpenRead())
            {
                this.editor.InsertImage(imageStream, droppedFile.Extension);
            }
        }
    }
}
 
private bool IsSupportedImageFormat(string extension)
{
    if (extension != null)
    {
        extension = extension.ToLower();
    }
 
    return extension == ".jpg" ||
        extension == ".jpeg" ||
        extension == ".png" ||
        extension == ".bmp";
}

This works on a PC in-browser. You can try it in the online demo.
If you have observed any issues, please let us know, so that we can investigate further.

Greetings,
Iva Toteva
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
RichTextBox
Asked by
Rob Ainscough
Top achievements
Rank 1
Answers by
TMatt
Top achievements
Rank 2
Iva Toteva
Telerik team
Share this question
or