Binding RadRichTextBox in WPF-MVVM to a viewmodel property

3 posts, 0 answers
  1. Kevin
    Kevin avatar
    9 posts
    Member since:
    Feb 2016

    Posted 29 Feb 2016 Link to this post

    Hello All,

          After hours of digging through the forums and help pages and examples, I have NOT found a complete example of how to bind a RadRichTextBox to a viewmodel property.  I would like to see a complete example , all the XAML and all the code in the viewmodel to setup the binding.  I think it should be fairly easy , all I want to do is display some simple text from my database (it's a property in the viewmodel) in a RadRichTextBox...  I'm sure I'll have to use a TxtFormatProvider for the control, but I can't seem to find a complete example of how to do this to bind to a viewmodel property.  The viewmodel property gets set on the viewmodels object instantiation .  I have looked at the Developer Focused Examples and found the data binding example , but that's not a View-View Model example.  

    Thanks in advance,

    Kevin Orcutt
    Senior Software Engineer

    Wurth Electronics ICS, Inc.
    7496 Webster St., Dayton, OH 45414
    Tel: 937.415.7700
    Toll Free: 877.690.2207
    Fax: 937.415.7710

  2. Vitalij
    Vitalij avatar
    35 posts
    Member since:
    Dec 2010

    Posted 01 Mar 2016 Link to this post

    Given I understand your question correctly, DataBinding example is indeed exactly what you are looking for. View is MainPage.xaml and ViewModel is ExampleDataContext.cs. All you need to tweak is how to load your document from database and set it to XamlData property of ViewModel.

    For all that to work, it is needed to store your generated document in xaml format in the database and not as plain text. Otherwise you would loose all text formatting when rebinding.

    If you are storing and saving plain text then maybe RadRichTextBox is not really what you need for display and edit your data.


    Best regards,


  3. Tanya
    Tanya avatar
    764 posts

    Posted 02 Mar 2016 Link to this post

    Hi Kevin and Vitalij,

    As Vitalij said, the Data Binding example demonstrates how a property from a view model could be bound to RadRichTextBox. The Document property is not a dependency property and in order to use it in a MVVM scenario, you will need to use one of the DataProviders. You could choose a data provider depending on the format you are planning to use for storing the document.

    Hope this makes things clear.

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