Two-Way Binding to the Html Property

5 posts, 0 answers
  1. WILLIAM
    WILLIAM avatar
    134 posts
    Member since:
    Jun 2012

    Posted 23 Apr 2013 Link to this post

    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!
  2. WILLIAM
    WILLIAM avatar
    134 posts
    Member since:
    Jun 2012

    Posted 23 Apr 2013 Link to this post

    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!!
  3. DevCraft banner
  4. Boby
    Admin
    Boby avatar
    595 posts

    Posted 24 Apr 2013 Link to this post

    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.

  5. WILLIAM
    WILLIAM avatar
    134 posts
    Member since:
    Jun 2012

    Posted 24 Apr 2013 Link to this post

    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.

    ??
  6. Boby
    Admin
    Boby avatar
    595 posts

    Posted 26 Apr 2013 Link to this post

    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.

Back to Top
DevCraft banner