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

RichTextBox "template" and dynamic regions

1 Answer 64 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Axelle
Top achievements
Rank 1
Axelle asked on 14 Apr 2014, 08:19 AM
Hello, 

I'm looking to implement a form of "print preview" function using RichTextBox : I want to edit by hand document template (at the moment they are in XAML, but any format would be acceptable) and to insert paragraphs or specific words coming from my software data.

I've successfully used DocumentVariable to update Specifific fields, but I don't understand how to place DocumentVariableFields in a template (I currently do it programattically). Moreover, I'm not sure they allow to insert whole formatted paragraphs. 

Is there a "right" way to achieve that using Telerik ? 

Thanks in advance, 

1 Answer, 1 is accepted

Sort by
0
Accepted
Missing User
answered on 16 Apr 2014, 01:39 PM
Hello,

Thank you for your interest in Telerik RadRichTextBox!

First, can you explain what do you mean by "don't understand how to place DocumentVariableFields in a template"? 

To your other question about formatted paragraphs - since you are already using document variable fields you can you to handle the DocumentVariableEvaluating event pf the RadDocument class. There you have full control over what the result of the field should be. In the event handler you can set the Result property of the DocumentVariableEvaluatingEventArgs to a DocumetnFragment you've created and this fragment will be used as a result of the field. This way you can have formatted content and even multiple paragraphs as a result of the document variable field.
Here is a code snippet that illustrates this approach. The result of the document variable field will be document fragment created form the document variable, but with heading style applied.
//Add a document variable
this.radRichTextBox.Document.DocumentVariables.Add("SpecificVariableName", "Custom result");
 
this.radRichTextBox.Document.DocumentVariableEvaluating += Document_DocumentVariableEvaluating;
...
//Insert a document variable field into the document
this.radRichTextBox.InsertField(new DocumentVariableField() { VariableName = "SpecificVariableName" });
...
void Document_DocumentVariableEvaluating(object sender, DocumentVariableEvaluatingEventArgs e)
{
if (e.VariableName == "SpecificVariableName")
{
object variable = e.Document.DocumentVariables["SpecificVariableName"];
 
RadDocumentEditor editor = new RadDocumentEditor(new RadDocument());
editor.Insert(variable.ToString());
 
// Change the style of the paragraph to Heading1
editor.ChangeStyleName(RadDocumentDefaultStyles.GetHeadingStyleNameByIndex(1));
 
e.Result = new DocumentFragment(editor.Document);
e.Handled = true;
}
}

I hope this helps! Let me know how it goes.

Regards,
Yancho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
RichTextBox
Asked by
Axelle
Top achievements
Rank 1
Answers by
Missing User
Share this question
or