Insert Formatted RTF text in caret position

Hi,

i need to add in WPF SfRichTextBoxAdv, formatted RTF text in caret position. I found only how add simple text with:
richTextBoxAdv.Selection.InsertText("Hello World!!!");
Is that a way to add formatted RTF text?

Thank you!

3 Replies

KC Karthikeyan Chandrasekar Syncfusion Team November 7, 2018 11:33 AM UTC

Hi Remigio, 
Currently SfRichTextBoxAdv doesn’t have API to insert formatted text. As a workaround, it can be achieved by creating formatted text as RTF and using paste command of SfRichTextBoxAdv.  
Step 1: Build RTF content for your formatted text. You can use DocIO library for this purpose. Kindly refer to UG link -https://help.syncfusion.com/file-formats/docio/overview 
Step 2: Set the RTF content in clipboard.  
Step 3: Invoke paste command.  
Code snippet:  
            SfRichTextBoxAdv richTextBoxAdv = new SfRichTextBoxAdv();  
            //Build RTF content for your formatted text.  
            string formattedText = @"{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs18\f2\cf0 \cf0\ql{\f2 {\b\ltrch Hello world}\li0\ri0\sa0\sb0\fi0\ql\par}{\f2 {\i\ltrch Welcome to WPF}\li0\ri0\sa0\sb0\fi0\ql\par}}}";  
            //Set RTF text in clipboard with format.  
            Clipboard.SetText(formattedText, TextDataFormat.Rtf);  
           Button insertText = new Button();  
            //Invoke the paste command.  
            insertText.Click += (object sender, RoutedEventArgs e) => { SfRichTextBoxAdv.PasteCommand.Execute(null, richTextBoxAdv); };  
              
Regards, 
Karthikeyan  



RF Remigio Fattori November 7, 2018 12:10 PM UTC

It works!

Thank you


KC Karthikeyan Chandrasekar Syncfusion Team November 7, 2018 12:12 PM UTC

You are welcome Remigio. 


Loader.
Up arrow icon