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

HtmlDataProvider + RadRTB, Html binding set called on init

5 Answers 145 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Claudio
Top achievements
Rank 1
Claudio asked on 28 Jul 2011, 11:17 AM
Hi everybody,
I have a problem with the Rich Text Box + HtmlDataProvider.
I make a simple an isolated example.

<telerikDocumentsHtml:HtmlDataProvider
            x:Name="provider"
            RichTextBox="{Binding ElementName=rtb}"
            Html="{Binding Text, Mode=TwoWay}" Grid.RowSpan="2" />
<telerik:RadRichTextBox Name="rtb" Margin="20"/>

This is my "main page" and the datacontext is setted to a simple class:

    public class ViewModel
    {
        private string text;
        public string Text
        {
            get { return text; }
            set 
            { 
                text = value; 
            }
        }
    }

the main page ctor works like this:

    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            var vm = new ViewModel();
            vm.Text = "XXXXXXXXXXX";
            DataContext = vm;
        }
    }


Seems that the SET accessor of the Text property is called TWICE, one during the first set on the ctor of the main page, the second from the binding in the Provider. 
If i use a normal textbox the binding set is not called on the beginning.
How can i avoid this?
Thanks to everybody.
Ray

5 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 02 Aug 2011, 04:48 PM
Hi Claudio,

This is currently the behavior by design. As the value of the string property you have bound the data provider to may not be valid HTML (which is also the case in your sample), we have decided to update the property with the result of the export the first time the Html property is updated. In this way, the value of the property in the view model will be synchronized with the content of the document at all times.
If you would like to suppress this update, you can download the source code of the controls from your account and implement your own data provider based on ours. Another option would be to implement a custom control containing a RadRichTextBox with a dependency property you can bind to which you can synchronize in an appropriate fashion.

Kind regards,
Iva
the Telerik team

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

0
Claudio
Top achievements
Rank 1
answered on 11 Aug 2011, 03:50 PM
Thank you for the suggestion, I will adopt a simple workaround to correct unwanted behaviors.
Claudio
0
Beaner
Top achievements
Rank 1
answered on 30 Aug 2011, 06:38 PM
I am having the exact same issue.  I'm tracking dirty screens using the HasChanges() on my domain context and because my string property is always being set twice, my screen is always dirty.  Do you have an example of a solution using a custom control with a dependency property?
0
Iva Toteva
Telerik team
answered on 05 Sep 2011, 10:10 AM
Hello Beaner,

Please find attached a sample application, which includes an implementation of a control encapsulating a RadRichTextBox. The conrol exposes a RichTextProperty which does not update the property it is bound to the first time the control is loaded.

Kind regards,
Iva
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Beaner
Top achievements
Rank 1
answered on 07 Sep 2011, 01:59 PM
Thank you!!
Tags
RichTextBox
Asked by
Claudio
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Claudio
Top achievements
Rank 1
Beaner
Top achievements
Rank 1
Share this question
or