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
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.
Iva
the Telerik team
<
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
>
<
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
What is Body in the following piece of code:
<
htmlProvider:HtmlDataProvider
...
Html
=
"{Binding Body, Mode=TwoWay}"
/>
Binding ElementName=StoreBlog
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
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:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
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
>
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.
Iva
the Telerik team