Paste issue in RadRichTextBox

0 Answers 54 Views
RichTextBox
Shraddha
Top achievements
Rank 1
Shraddha asked on 24 May 2024, 05:11 AM

RadRichTextBox is not allowing copy pasting from different document and also from another RadRichTextBox. 
If I am copying from same RadRichTextBox and then pasting it to same RadRichTextBox, then it is working fine.

So, I took reference from below doc:

WPF RichTextBox - Clipboard Support - Telerik UI for WPF

and implemented below function:

private void RadRichTextBox_CommandExecuting(object sender, CommandExecutingEventArgs e) 
{ 
    if (e.Command is PasteCommand) 
    { 
        e.Cancel = true; 
        // Obtain the document inside the clipboard 
        RadDocument document = ClipboardEx.GetDocument().ToDocument(); 
 
        // Change it according to your needs 
        document.Selection.SelectAll(); 
        RadDocumentEditor editor = new RadDocumentEditor(document); 
        editor.ChangeFontSize(Unit.PointToDip(12)); 
 
        // Insert it in RadRichTextBox 
        this.radRichTextBox.InsertFragment(new DocumentFragment(document)); 
    } 
} 


I observed that if I am copying from another doc and pasting to that RadRichTextBox then 

RadDocument document = ClipboardEx.GetDocument().ToDocument(); 

this line is giving System.NullReferenceException: 'Object reference not set to an instance of an object.'

How to fix this?

Shraddha
Top achievements
Rank 1
commented on 24 May 2024, 05:36 AM

No answers yet. Maybe you can help?

Tags
RichTextBox
Asked by
Shraddha
Top achievements
Rank 1
Share this question
or