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

Two-Way Binding to the Html Property

4 Answers 78 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
WILLIAM
Top achievements
Rank 1
WILLIAM asked on 23 Apr 2013, 04:51 PM
Hi Telerik Team,

I'm having trouble binding to the RadRichTextBox.  I'm using the HtmlDataProvider and I'm binding (two-way) to the Html property.  I'm subscribing to the DocumentContentChanged even tot attempt to clean certain characters (the upside down ?).  The problem is at the time this event is fired, the upside down ? is not yet part of the html property but they are displayed in the editor.

Am I binding to the correct property?
Is there an event that I can subscribe to where what is displayed in the editor is the same as the text in the Html property so that I can remove those charactes?

Thanks for your help!

4 Answers, 1 is accepted

Sort by
0
WILLIAM
Top achievements
Rank 1
answered on 23 Apr 2013, 06:30 PM
I'm calling Export(RadRichTextBox.Document) to get the current contents of the document, then I'm cleaning the bad characters, and then Importing the cleaned source.  But this doesn't seem to work.  Subsequent  calls to Export() returns the original value as if nothing ever happened.

  1. Shouldn't calling Import(source) update the Document with the updated value?
  2. What property do I set after I've cleaned the source to update the document. 

var source = HtmlDataProvider.FormatProvider.Export(RadRichTextBox.Document);
source = CleanSource(source);
HtmlDataProvider.FormatProvider.Import(source);

Thanks!!
0
Boby
Telerik team
answered on 24 Apr 2013, 08:48 AM
Hello William,
You can use the SetupDocument event of the data provider to do some post-processing of the document just after the import.
Also it seems reasonable to replace the inverted question marks directly in the source - this should be easy as they don't have any special meaning and you can just replace all occurrences.

Regards,
Boby
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
WILLIAM
Top achievements
Rank 1
answered on 24 Apr 2013, 01:00 PM
The code snippet above is being called on the SetupDocument event.  The issue is that when the Html property is set, the source has the question marks removed, but they are still visible in the control; and if I do another Export(RRTB.Document), the source is the original source with question marks, not the version without them.

??
0
Boby
Telerik team
answered on 26 Apr 2013, 08:27 AM
Hello William,
I can understand the confusion now. SetupDocument event should be used for post-processing the document after import and before setting it to the associated RadRichTextBox.
If you want to modify the source itself, it may be more appropriate to do this before the binding occur, for example in the getter of the source property in the ViewModel.
You can also choose to clean the symbols from the already imported document in the SetupDocument event handler, for example using the Find/Replace mechanism.

Regards,
Boby
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
WILLIAM
Top achievements
Rank 1
Answers by
WILLIAM
Top achievements
Rank 1
Boby
Telerik team
Share this question
or