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

Document Databinding and HtmlDataProvider updating

2 Answers 148 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Dave Perrill
Top achievements
Rank 1
Dave Perrill asked on 04 Oct 2011, 01:02 PM
Hi
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); }
            set
            {
                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.htmlDataProvider.UpdateDocument();
            this.HtmlString = this.htmlDataProvider.Html; 
        }

2 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 07 Oct 2011, 12:02 PM
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,
Iva
the Telerik team

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

0
boroo
Top achievements
Rank 1
answered on 03 Apr 2013, 02:10 AM
Thank you, very much...
Tags
RichTextBox
Asked by
Dave Perrill
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
boroo
Top achievements
Rank 1
Share this question
or