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

Bind a richtextbox to html using ria service

5 Answers 147 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Shane P
Top achievements
Rank 1
Shane P asked on 29 Nov 2010, 11:03 AM
Hey there,
I have created a richtext which exports the data out as html using ria ok. My question is how do I bind the richtextbox using ria to the html thats saved in my db? I want to when my application loads pull the html thats stored within my db and render it inside the textbox.

I am using the latest version Q3 2010, any help would be great!

5 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 29 Nov 2010, 05:14 PM
Hi Shane P,

RadRichTextBox provides data binding through DataProviders. There is a demo illustrating how exactly is that done in this forum thread (the last post). The sample project there uses XamlDataProvider but since all DataProviders work in the same manner, you can adopt that approach with HtmlDataProvider as well.
Try it out and let us know if you experience any difficulties.

Kind regards,
Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Shane P
Top achievements
Rank 1
answered on 11 Dec 2010, 11:25 PM
Ok so I just got back to trying to sort this without to much joy. This is what I have so far but sadlly its not working. No errors just not working

<telerik:RadRichTextBox  x:Name="editor"
                                      AllowDrop="True"
                                  DocumentInheritsDefaultStyleSettings="True"
                                 FontFamily="Verdana"
                                 FontSize="10"
                                   IsContextMenuEnabled="False"
                                 IsSpellCheckingEnabled="False"
                                  IsSelectionMiniToolBarEnabled="False">
               <telerik:RadRichTextBox.Resources>
                   <htmlProvider:HtmlDataProvider x:Key="HtmlProvider" RichTextBox="{Binding ElementName=StoreBlog}" Html="{Binding Body,Mode=TwoWay}"/>
               </telerik:RadRichTextBox.Resources>
           </telerik:RadRichTextBox>
my domain datasource
<riaControls:DomainDataSource AutoLoad="True"
                                  Height="0"
                     Name="documentDomainDataSource"
                                  QueryName="GetStoreBlobsQuery">
            <riaControls:DomainDataSource.DomainContext>
                <my:SPDomainContext x:Name="documentDataContext"/>
            </riaControls:DomainDataSource.DomainContext>
        </riaControls:DomainDataSource>

Any advise would be most helpful.

Thank you
0
Iva Toteva
Telerik team
answered on 13 Dec 2010, 04:58 PM
Hi Shane P,

What is Body in the following piece of code:

<htmlProvider:HtmlDataProvider ... Html="{Binding Body, Mode=TwoWay}"/>
If you had seen that in our help article, you should have in mind that the snippet there does not represent a full example and is just setting some guidelines. It assumes that you have set the DataContext and/or the ItemsSource to some collection of objects and Body is a property of these objects. Also the binding:
Binding ElementName=StoreBlog
should match the name of the RadRichTextBox instance, which in this case is "editor".

Unfortunately in Silverlight 4 binding errors are not reported and cannot be debugged. The latest news form MS point out that this will be improved in Silverlight 5.

Are you able to show the text in a TextBox with the same binding? If that is so, we would be able to provide you with better assistance if you open a support ticket and send over a sample demo.

Kind regards,
Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Matt Greer
Top achievements
Rank 1
answered on 15 Dec 2010, 09:37 PM
I am trying to do this too without much luck. I can't even get the Db example posted in the other thread to work correctly.

I am complicating this a bit by wanting to have the RadRichTextBox in a control.

So if I have a UserControl called MyRichTextEditor that contains
a toolbar
RadRichTextBox
and a DependencyProperty named RichText, how can I have the RichText property be bound to the content of RadRichTextBox?

I want to be able to do
<my:MyRichTextEditor RichText="{Binding SomeValue, Mode=TwoWay}" />

and have that get bound into my RadRichTextBox. As it stands now, I can't get anything to show up in the RadRichTextBox at all, even a canned string. Is having it in a UserControl complicating things?

Why is the HtmlProvider defined in Resources?



My control is:

<UserControl x:Class="Navigator.Views.Controls.NavRichTextBox"
    xmlns:documentsHtml="clr-namespace:Telerik.Windows.Documents.FormatProviders.Html;assembly=Telerik.Windows.Documents.FormatProviders.Html"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
 
    <UserControl.Resources>
        <documentsHtml:HtmlDataProvider x:Key="HtmlDataProvider" RichTextBox="{Binding ElementName=_richTextBox}" Html="hello there" />
    </UserControl.Resources>
     
    <Border BorderBrush="Black" BorderThickness="1" x:Name="LayoutRoot" Background="White">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
 
            <StackPanel x:Name="_formattingToolBar" Grid.Row="0" Orientation="Horizontal" Background="LightGray">
                <telerik:RadRibbonToggleButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=Commands.ToggleBoldCommand, ElementName=_richTextBox}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/bold.png" />
                <telerik:RadRibbonToggleButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=Commands.ToggleItalicCommand, ElementName=_richTextBox}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/italic.png" />
                <telerik:RadRibbonToggleButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=Commands.ToggleUnderlineCommand, ElementName=_richTextBox}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/underline.png" />
            </StackPanel>
 
            <telerik:RadRichTextBox x:Name="_richTextBox" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
            </telerik:RadRichTextBox>
 
            <StackPanel Grid.Row="2" Orientation="Horizontal">
                <TextBlock Text="Footer here" />
            </StackPanel>
        </Grid>
    </Border>
</UserControl>
0
Iva Toteva
Telerik team
answered on 21 Dec 2010, 08:26 AM
Hello Matt Greer,

RadRichTextBox uses DataProviders in order to allow import from and export to different file formats - HTML, DOCX, XAML and plain text. Introducing a RichText property might cause many unexpected difficulties.

In your case, setting an explicit value to the Html property, breaks the binding. I am attaching a demo, illustrating an approach that works for Two-Way Binding. Currently, the DataProviders only support two-way binding, but we will fix that, hopefully for the Service Pack coming in a week or so.

Best wishes,
Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
RichTextBox
Asked by
Shane P
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Shane P
Top achievements
Rank 1
Matt Greer
Top achievements
Rank 1
Share this question
or