Bind RichTextBox to Database / Object

4 posts, 0 answers
  1. Frank
    Frank avatar
    7 posts
    Member since:
    Aug 2010

    Posted 05 Oct 2010 Link to this post

    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"/>
  2. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 07 Oct 2010 Link to this post

    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
  3. Frank
    Frank avatar
    7 posts
    Member since:
    Aug 2010

    Posted 07 Oct 2010 Link to this post

    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!
  4. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 08 Oct 2010 Link to this post

    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
Back to Top