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

Binding problem

2 Answers 45 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Fredrik
Top achievements
Rank 2
Fredrik asked on 06 Jan 2016, 09:20 AM

Hello am using RichTextBox and the htmldataprovider for binding directly to a property on a db entity.

<telerikHtml:HtmlDataProvider Name="htmlDataProvider" RichTextBox="{Binding ElementName=radRichTextBox}" Html="{Binding Entity.HtmlProperty,Mode=TwoWay}" />

My Entity.HtmlProperty can allready contain html text data to be displayed so i need to be a two way binding.

 

My problem:

RichTextBox is not present in the visual tree initially by the application page. it gets presented in a slide in panel on demand.

Meaning the data of my existing property is loaded before the RichTextBox  is presented

Due to slow loading of the RichTextBox or some other reason my existing data content gets replaced by RichTextBox empty html content(even if nothing is typed, there still is a bunch of html code)

Is there any non dirty way to resolve this probem?

(one option I can think of is to is to trap the loaded event and add the binding to the HtmlDataProvider in code, but am not sure how to do this?)

2 Answers, 1 is accepted

Sort by
0
Fredrik
Top achievements
Rank 2
answered on 06 Jan 2016, 01:41 PM

Got this working, might be the best solution

private async Task LoadRichTextBox(object par)
        {
       
                var rtb = par as RadRichTextBox;

                Binding b = new Binding("Entity.Html");
                b.Source = EntityCarrier;
                b.Mode = BindingMode.TwoWay;

                HtmlDataProvider hdp = new HtmlDataProvider();
                hdp.RichTextBox = rtb;
                hdp.SetBinding(HtmlDataProvider.HtmlProperty, b);

        }

0
Todor
Telerik team
answered on 07 Jan 2016, 09:08 AM
Hi Fredrik,

Since the RadRichTextBox is added later to the visual tree, the solution you found to make the things working properly is a correct one. 

If you have further questions, please do not hesitate to contact us again.

Regards,
Todor
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Fredrik
Top achievements
Rank 2
Answers by
Fredrik
Top achievements
Rank 2
Todor
Telerik team
Share this question
or