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

RadRichTextBox - Change specific style properties of pasted paragraphs

1 Answer 85 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 07 Oct 2015, 08:43 PM

Hello,

I'm seeking a way to strip a paragraph's SpacingBefore and SpacingAfter properties when pasted into a RichTextBox from an outside source. So far all my attempts at intercepting these properties have proven futile. I've searched these forums for various ways of handling pasted data, yet none have proven effective for my particular situation. I've attempted to enumerate through the document's paragraphs and set each paragraph's SpacingBefore/After property to 0, I've attempted to change the paragraph's properties in the PastCommand handler while enumerating through paragraphs' Inlines to remove certain types (the removal works here, but not the set properties).

I'm hoping to gain advice on how this should be properly done. I can include some code snippets if that would be helpful.

 

Thank you,

Steve

 

P.S: It might also be helpful to mention the need for this came after upgrading from Telerik version 2014.1.0224.45 to version 2015.2.728.45, where the outside source styling did not carry into the RichTextBox.

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 09 Oct 2015, 08:19 AM
Hi Steve,

Thank you for the provided detailed information.

I've tried to reproduce the unexpected behavior during copy/paste, but to no avail. Everything works as expected with the version you've pointed (2015.2.728.45) as problematic and with the version from our latest release (2015.3.9.30).

However, if you desire to change the content of the clipboard when pasting in RadRichTextBox, you could attach to the RadRichTextBox.CommandExecuting event and the event handler could look like the following one:
private void RadRichTextBox_CommandExecuting(object sender, CommandExecutingEventArgs e)
{
    if (e.Command is PasteCommand)
    {
        DocumentFragment fragment = ClipboardEx.GetDocument();
        foreach (Paragraph paragraph in fragment.EnumerateChildrenOfType<Paragraph>())
        {
            paragraph.SpacingAfter = 0;
            paragraph.SpacingBefore = 0;
        }
 
        ClipboardEx.SetDocument(fragment);
    }
}


I hope this helps.
If you need further assistance, please get back to us again.

Regards,
Todor
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Steve
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or