This is a migrated thread and some comments may be shown as answers.

How to: MVVM?

5 Answers 265 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Larry
Top achievements
Rank 1
Iron
Iron
Veteran
Larry asked on 24 Oct 2020, 01:19 AM

Sorry if this is a real newbie question...

How do I use RichTextEditor with MVVM?  I'm not using an MVVM implementation (Fresh, etc.), I just want to bind the text (html) of the control to my view model but I'm stumped.  Thanks.

5 Answers, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 26 Oct 2020, 11:00 AM

Hi Larry,

How to bind the Source property of the RichTexteditor component, You can check the RichTextEditor examples in our Telerik Xamarin Samples Application. 

FirstLook Example: https://github.com/telerik/telerik-xamarin-forms-samples/blob/master/QSF/QSF/Examples/RichTextEditorControl/FirstLookExample/FirstLookView.xaml#L64 https://github.com/telerik/telerik-xamarin-forms-samples/blob/master/QSF/QSF/Examples/RichTextEditorControl/FirstLookExample/FirstLookViewModel.cs#L58

CustomizationExmaple: https://github.com/telerik/telerik-xamarin-forms-samples/blob/master/QSF/QSF/Examples/RichTextEditorControl/CustomizationExample/CustomizationView.xaml#L56 

https://github.com/telerik/telerik-xamarin-forms-samples/blob/master/QSF/QSF/Examples/RichTextEditorControl/CustomizationExample/CustomizationViewModel.cs#L26

I hope the provided information will be helpful.

Regards,
Didi
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Larry
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 27 Oct 2020, 01:30 AM
Thanks.  I saw how to 'supply' text by binding to Source. However, what I need is to display a blank editor and then 'get' the text that's been entered (from the view model).
0
Didi
Telerik team
answered on 27 Oct 2020, 09:58 AM

Hello Larry,

Thank you for the provided additional information about the scenario you want to achieve. 

As you want to get the content inside the RichText editor component, you can check our Import/Export example. For the demo, we have implemented IRickTextContext interface with GetHtmlAsyn, for the SaveCommand. Please review the example and its implementation. Note that it's up to you how to get the context. The demo is just an example of how this could be achieved. 

Import/Export Demo https://github.com/telerik/telerik-xamarin-forms-samples/tree/master/QSF/QSF/Examples/RichTextEditorControl/ImportExportExample 

IRichTextContext interface and RichTextContext.cs file

I hope this will help.

Regards,
Didi
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Larry
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 27 Oct 2020, 07:32 PM
Thanks, I was able to get to a solution. However, it (my code and the example code) is way too convoluted.  Being able to retrieve (bind to) the text should be simple and straight forward.  I hope some effort goes into this before the control is brought out of beta.  For the moment, I have a solution so thanks much for that!
0
Ivan
Telerik team
answered on 28 Oct 2020, 10:29 AM

Hello Larry,

Actually, providing a bindable property for the HTML content was discussed among us when designing the control. The problem with such approach and the reason we were hesitant to implement it was due to performance and memory efficiency. 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. On top of that, we would have to update that property for just in case, even if the application is not actually using it, simply because we do not know whether it is used in data binding or not.

Also, converting the HTML DOM of the WebView to a regular string has an inherent cost that is not trivial, and communicating between the C# code and the native WebView is asynchronous in nature. We would rather not try to hide that cost from the developer, hence the asynchronous method. When calling GetSomethingAsync it is clear that the operation is expensive and asynchronous. When using a property that cost is hidden and it would be unclear why performing an edit operation won't be reflected immediately to the property.

Considering all this, we decided that introducing a bindable property would be not a good API design.

Regards,
Ivan
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
RichTextEditor
Asked by
Larry
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Didi
Telerik team
Larry
Top achievements
Rank 1
Iron
Iron
Veteran
Ivan
Telerik team
Share this question
or