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

RadDocument generated in code - Binding

2 Answers 135 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 19 Dec 2011, 05:20 PM

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 Answers, 1 is accepted

Sort by
0
Justin Lee
Top achievements
Rank 1
answered on 19 Dec 2011, 06:30 PM
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
0
Iva Toteva
Telerik team
answered on 20 Dec 2011, 03:00 PM
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 >>

Tags
RichTextBox
Asked by
Justin Lee
Top achievements
Rank 1
Answers by
Justin Lee
Top achievements
Rank 1
Iva Toteva
Telerik team
Share this question
or