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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to implement RtfText property for SfRichTextBoxAdv control?

Platform: UWP |
Control: SfRichTextBoxAdv

You can bind Rtf text with SfRichTextBoxAdv content by implementing an extension class with RtfText property.

Please refer the following code samples.

C#

 

XAML

 

 

2X faster development

The ultimate UWP UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Koen Janssens
May 13, 2022

Hi,

I had to add a part to clear the textbox when the bound field was empty. Without this, when scrolling through a set of records of which a field is bound, the last non-empty value staid in the textbox.

        private void UpdateDocument(string rtfText)
        {
            // If Rtf text property is set internally means, skip updating the document.
            if (!skipUpdating && !string.IsNullOrEmpty(rtfText))
            {
                Stream stream = new MemoryStream();
                // Convert the Rtf string to byte array.
                byte[] bytes = Encoding.UTF8.GetBytes(rtfText);
                // Writes the byte array to stream.
                stream.Write(bytes, 0, bytes.Length);
                stream.Position = 0;
                //Load the Rtf stream.
                Load(stream, FormatType.Rtf);
            }
            else if (string.IsNullOrEmpty(rtfText))
            {

                Load(new MemoryStream(), FormatType.Rtf);
            }
        }
Reply
Premkumar Sundaramoorthy [Syncfusion]
May 16, 2022

Hi Koen,

From your code snippet and details we suspect that you want to clear the document content when the input/source RTF text is empty. So, you can use the NewDocument command. Please refer the below code snippet and API reference for more details.

code example

 private void UpdateDocument(string rtfText)
        {
            // If Rtf text property is set internally means, skip updating the document.
            if (!skipUpdating && !string.IsNullOrEmpty(rtfText))
            {
                Stream stream = new MemoryStream();
                // Convert the Rtf string to byte array.
                byte[] bytes = Encoding.UTF8.GetBytes(rtfText);
                // Writes the byte array to stream.
                stream.Write(bytes, 0, bytes.Length);
                stream.Position = 0;
                //Load the Rtf stream.
                Load(stream, FormatType.Rtf);
            }
            else if (string.IsNullOrEmpty(rtfText))
            {
                **this.NewDocumentCommand.Execute(null);**
            }
        }

new document command API reference

If your requirement is different, please share more details we will update you the appropriate solution.

Regards, Premkumar

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile