RichTextEditor Data Binding Issue

1 Answer 132 Views
RichTextEditor
Angelica
Top achievements
Rank 1
Iron
Angelica asked on 15 Dec 2023, 03:46 PM

I am using the RichTextEditor in our .NET MAUI app and have the following:

  <telerik:RadRichTextEditor
      x:Name="paragraphEditor"
      Grid.Row="1"
      AutomationId="Editor"
      BorderColor="{StaticResource Primary}"
      BorderThickness="1"
      Source="{Binding Test.TestWriteupHTML}" />

public class Test: INotifyPropertyChanged
{
    private string? _testWriteupHTML;

    public string? TestWriteupHTML
    {
        get => _testWriteupHTML;
        set
        {
            if (_testWriteupHTML != value)
            {
                _testWriteupHTML = value;
                OnPropertyChanged(nameof(TestWriteupHTML));
            }
        }
    }
}

I have a method to update the TestWriteupHTMP property, while debugging I can see that it gets updated properly but on the UI the editor is not updating, any suggestions? 

1 Answer, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 19 Dec 2023, 06:30 AM

Hi Angelica,

The Source property of the RichTextEditor works one way and this is by design. Let me explain in more details - RichTextEditor serves as a html editor, it receives as a source html content and provides means for the users to modify the formatting and text.  After certain formatting, for example font change, is applied, this does not immediately update the source html ( that's why when using Two-way binding, the property the Source is bound to, is not updated as well). 

You can see visually how the content will look after the change, however,  the updated html can be generated only when you explicitly call the GetHtmlAsync() method. If the RichTextEditor updates the source html on every formatting action or keystroke, this would lead to degraded performance.

Consider the scenario when you have a relatively big HTML content, say 30MB (that can easily happen if you have even a single image in it). Then on every keystroke, we need to update the value of that property, thus allocating another 30MB string to replace the original one. Clearly, this is not very efficient and would cause the garbage collector to run constantly, hampering the overall performance of the application.

I would suggest you take a look at our Import/Export example inside the Controls Samples App - it shows a sample approach how you can load html content and get the updated html. For the demo, we have implemented IRichTextContext interface with GetHtmlAsync method, for the SaveCommand

Regards,
Didi
Progress Telerik

A brand new .NET MAUI course was just added to the Virtual Classroom. The training course is developed to help you get started with the Telerik UI for .NET MAUI components and features. It aims to put you in the shoes of an engineer who adds new features to an existing application. You can check it out at https://learn.telerik.com
Tags
RichTextEditor
Asked by
Angelica
Top achievements
Rank 1
Iron
Answers by
Didi
Telerik team
Share this question
or