We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Insert Formatted RTF text in caret position


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); };  

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. 

Live Chat Icon For mobile
Up arrow icon