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

Bind RichTextBox to Database / Object

3 Answers 374 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Frank
Top achievements
Rank 1
Frank asked on 05 Oct 2010, 08:30 PM
Hello,

how can I bind a RichTextBox to a database / object?

I've tried this:
http://www.telerik.com/help/silverlight/radrichtextbox-how-to-binding-to-data-providers.html

The saving (to the object/db) of the RichTextBox contents works fine. (HTML and XAML).
But I cannot load the context from the database.

The RichTextbox remains blank.

Any ideas?
Thank you!


    xmlns:documents="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Documents"
    xmlns:documentsHtml="clr-namespace:Telerik.Windows.Documents.FormatProviders.Html;assembly=Telerik.Windows.Documents.FormatProviders.Html"


    <UserControl.Resources>
        <documentsHtml:HtmlDataProvider x:Key="xamlDataProvider"
                                        RichTextBox="{Binding ElementName=richTextBox}"
                                        Html="{Binding Item.Comment, Mode=TwoWay}" />
    </UserControl.Resources>

 
<documents:RadRichTextBox Name="richTextBox"/>

3 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 07 Oct 2010, 03:58 PM
Hello Frank,

I am sorry but I am not quite sure I understand what you mean. Do you have trouble loading the data from the database to the data context, or binding a RadRichTextBox to an object in code-behind/ database?

First of all, make sure you are using SP2, as there were issues with the two-way binding in SP1.

If you want to use WCF/ RIA services, refer to:
http://www.telerik.com/community/forums/silverlight/general-discussions/keeping-format-of-msword.aspx

And if you want to bind the RadRichTextBox to an object you have in code-behind, you just need to add in codebehind 
this.richTextBox.DataContext = item;
and assign the binding to Comment and not Item.Comment, like this:
<documentsHtml:HtmlDataProvider x:Key="htmlDataProvider" RichTextBox="{Binding ElementName=richTextBox}" Html="{Binding Comment, Mode=TwoWay}" />
However, the object you are binding to (item in this case) must implement INotifyPropertyChanged. You can see in the attached demo how to do that.


Let us know if that helped you solve your issue or you need further assistance.


Best wishes,
Iva
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Frank
Top achievements
Rank 1
answered on 07 Oct 2010, 09:35 PM
Dear Iva,

thank you for your replay.
You are right, my description was not good.

In other words:
I like to bind the "Value" of the RichTextBox to a Property of an Object.

e.g:
public class Order
{
   public Guid Id {get;set;}
   public Guid Customer {get;set;}
   public string Comment {get;set;}
}

The "Value" of the RichTextBox should be bind to Order.Comment.

For a regular TextBox you would do this:
<TextBox Text="{Binding Item.Comment}"/>

Thank you!
0
Iva Toteva
Telerik team
answered on 08 Oct 2010, 04:58 PM
Hi Frank,

You can use the very same binding, but this time you should be assigning it to the appropriate property of the specific DataProvider (e.g. the "Html" property of HtmlDataProvider). Also, you should attach the DataProvider to the RadRichTextBox as shown in the article on binding which you have discovered yourself. Please note that binding to a regular property (rather than DependencyProperty) will only work one-way. Two-way binding requires a DependencyProperty or an object implementing INotifyPropertyChanged.
More on this you can find also in the RadRichTextBox section in our Silverlight demo suit.
If you need further assistance, do not hesitate to get back to us.

Regards,
Iva
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Frank
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Frank
Top achievements
Rank 1
Share this question
or