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

3 posts, 0 answers
  1. Rob Ainscough
    Rob Ainscough avatar
    231 posts
    Member since:
    Jan 2010

    Posted 02 Mar 2012 Link to this post

    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. TMatt
    TMatt avatar
    46 posts
    Member since:
    Feb 2011

    Posted 04 Mar 2012 Link to this post

    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.
  3. Iva Toteva
    Iva Toteva avatar
    1319 posts

    Posted 05 Mar 2012 Link to this post

    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.

    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 >>
Back to Top