RadDocument generated in code - Binding

3 posts, 0 answers
  1. Justin Lee
    Justin Lee avatar
    169 posts
    Member since:
    Dec 2009

    Posted 19 Dec 2011 Link to this post

    I'm working on an application that dynamically creates a RadDocument, and then sets the document property of a RichTextBox to the document. (richTextBox.Document = GenerateDocument())

    Recently we switched to mvvm.  So I didn't have to rewrite all the code, I just create the RadDocument in the ViewModel and expose it as a property.  However, I am unable to bind the document to the richtextbox.  ('System.WIndows.Data.Binding' cannot be converted to type 'Telerik.WIndows.Documents.Model.RadDocument')

    What can I do to fix this without rewriting my code to return html or xaml instead?

    public class ViewModel
    {
      private RadDocuement _Document;
      public RadDocument Document
      {
        get
        {
          if (_Document == null)
            _Document = GenerateDocument();
          return _Document;
        }
      }
     
      private RadDocuement GenerateDocument()
      {
        RadDocument doc = new RadDocument();
        // add sections, paragraphs, etc
        return doc;
      }
    }

    <telerik:RadRichTextBox Document="{Binding Path=Report.Document}" IsReadOnly="True" />

  2. Justin Lee
    Justin Lee avatar
    169 posts
    Member since:
    Dec 2009

    Posted 19 Dec 2011 Link to this post

    Nevermind... I have found a solution - I created a custom class that inherited from RadRichTextBox, and exposed a DocumentBinding dependancy property. 

    Sorry for the spam.
    Justin
  3. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 20 Dec 2011 Link to this post

    Hi Justin,

    RadRichTextBox uses data providers in order to be able to bind its content to strings representing a document in a specific format.

    If the solution you have found suits your needs, you can use that approach instead of the data providers.

    Best wishes,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top