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

Setting default WrappingStyle for Images

3 Answers 86 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Andi
Top achievements
Rank 1
Andi asked on 24 Feb 2021, 04:20 PM

Hi there,

we want to change the default WrappingStyle when inserting images.
The images are inserted via Copy&Paste or Drag&Drop.

They should all have WrappingStyle "Square" when inserted (and not WrappingStyle "In line with text").

What is the simplest solution to do this?

Thank you, Andi

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 25 Feb 2021, 01:45 PM

Hi Andi,

You can use the CommandExecuted event and if an image is pasted change the wrapping. Here is an example of this: 

private void RadRichTextBox_CommandExecuted(object sender, CommandExecutedEventArgs e)
{
    if (e.Command is PasteCommand)
    {
        var currentElement = radRichTextBox.Document.CaretPosition.GetPreviousInline();
        if (currentElement is ImageInline)
        {
            var command = new ChangeImageWrappingStyleCommand(radRichTextBox);
            radRichTextBox.Document.CaretPosition.MoveToInline(currentElement);
            command.Execute(WrappingStyle.Square);
        }
    }
}

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Andi
Top achievements
Rank 1
answered on 26 Feb 2021, 01:04 PM

Hi Dimitar,

we did not get the CommandExecuted Command, because we had a event handler for 

private async void OnPaste(object aSender, ExecutedRoutedEventArgs aEventArgs) {
    ...
                                      // extensions of DataObject ;-)   
    else if (Clipboard.GetDataObject().ContainsBitmapSource(true))
    {
        var imageInline =
             new  ImageInline(new WriteableBitmap(Clipboard.GetDataObject().GetBitmapSource()));
        var floatingBlock = new FloatingImageBlock {
                ImageInline = imageInline,
                WrappingStyle = WrappingStyle.Square
        };
        mRichTextBox.InsertInline(floatingBlock);
    }
    else
    {
        mRichTextBox.Insert(Clipboard.GetText());
    }
}
0
Andi
Top achievements
Rank 1
answered on 26 Feb 2021, 02:02 PM

Sorry - too fast and it is not possible to edit again.

So this is my solution and it works.

Thank you and bye, Andi

Tags
RichTextBox
Asked by
Andi
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Andi
Top achievements
Rank 1
Share this question
or