Document Databinding and HtmlDataProvider updating

3 posts, 0 answers
  1. Dave Perrill
    Dave Perrill avatar
    9 posts
    Member since:
    Apr 2011

    Posted 04 Oct 2011 Link to this post

    I have the following code which I am using to bind to the RichTextBox, but the actual HTML from the HtmlDataProvider is not updated at the time that the DocumentContentChanged event is fired. How can I force this update or is there an event that I can attach to that is fired after the HtmlDataProvider html is updated.

    public string HtmlString
                get { return (string)this.GetValue(HtmlStringProperty); }
                    this.SetValue(HtmlStringProperty, value);
            public static readonly DependencyProperty HtmlStringProperty = DependencyProperty.Register(
              "HtmlString", typeof(string), typeof(RichTextEditorUC), new PropertyMetadata(null, OnHtmlStringChanged));
            private static void OnHtmlStringChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
                RichTextEditorUC parent = d as RichTextEditorUC;
                if (e.NewValue != null)
                    if (parent.htmlDataProvider.Html != e.NewValue as string)
                        parent.htmlDataProvider.Html = e.NewValue as string;
    private void editor_DocumentContentChanged(object sender, System.EventArgs e)
                this.HtmlString = this.htmlDataProvider.Html; 
  2. Iva Toteva
    Iva Toteva avatar
    1319 posts

    Posted 07 Oct 2011 Link to this post

    Hello Vikram,

    Please find attached a sample implementation of a RichTextControl, which inherits from RadRichTextBox and exposes an HtmlString dependency property
    . In the example HtmlFormatProvider is used instead of HtmlDataProvider, because the document and the string property need to be updated explicitly and the use of the DataProvider does not simplify the task. Furthermore, the data provider uses the same events to update its properties and document, so this logic will be duplicated, i.e. change in the document -> change in the Html property of the provider -> update in your property. Using HtmlFormatProvider results in skipping an unnecessary step.
    I hope this helps.

    Kind regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft R3 2016 release webinar banner
  4. boroo
    boroo avatar
    1 posts
    Member since:
    Apr 2010

    Posted 02 Apr 2013 Link to this post

    Thank you, very much...
Back to Top