6 Answers, 1 is accepted
There is a demo of a MS Word-like use of the rich text box together with the ribbon at http://demos.telerik.com/silverlight/beta/#RichTextBox/MSWord. You can view the code used for creating the demo by clicking "View code" in the top-right corner. This example is also included in the sample projects which are included in the installation zips. You can download it from your account.
Import from and export to doc are currently not supported and have not been scheduled, i.e. it has yet to be determined if and when they will be implemented. For a list of the available file formats, you can refer to this help article.
If we can help you with anything else, do not hesitate to get back to us.
Iva
the Telerik team
Where can I find the stand alone MSword example for silverlight RadRichtextbox?
Also I would like to build a letter (like an email) dynamically inside the RadRichtextbox (which looks like a MS word). Kindly guide me to an example.
Thank you in advance for your reply.
Tom
Please find attached a stand-alone MsWord example of the rich text box for Silverlight. It pretty much copies the code from the examples, included in the installation for Q1 2011 (2011.1.315).
As for dynamically building the content of document, that can be done through RadRichTextBox's and RadDocument's API. This forum thread deals exclusively with code-behind manipulation of the document before it is shown in a rich text box. There is also a small demo in one of the first posts, that can help you get started. Basically, you can manipulate the Children/ Inlines/ Blocks properties of the different document elements before the document is measured and arranged (which happens once the document is shown in the editor). After that, you can use the methods from the API (InsertInline(), Insert(), etc.).
Iva
the Telerik team
Hi Iva:
Thank you. That was very helpfull. I have used following code to generate document code. But it doesnt seem to render rightly.
Is this approach is correct?
======================================================================
RadDocument doc = new RadDocument();
doc.LayoutMode = DocumentLayoutMode.Paged;
Telerik.Windows.Documents.Model.Section section = new Telerik.Windows.Documents.Model.Section();
doc.Sections.Add(section);
doc.SectionDefaultPageMargin = new Telerik.Windows.Documents.Layout.Padding(50, 50, 50, 50);
///Build To Address
Telerik.Windows.Documents.Model.Paragraph paragraph = new Telerik.Windows.Documents.Model.Paragraph();
section.Blocks.Add(paragraph);
Telerik.Windows.Documents.Model.Span spanTo = new Telerik.Windows.Documents.Model.Span();
spanTo.FontSize = 10;
spanTo.Text = "To," + "\r\n";
paragraph.Inlines.Add(spanTo);
Telerik.Windows.Documents.Model.Span spanRefPhy = new Telerik.Windows.Documents.Model.Span();
spanRefPhy.FontSize = 10;
spanRefPhy.Text = referringPhysician + "\r\n";
paragraph.Inlines.Add(spanRefPhy);
Telerik.Windows.Documents.Model.Span orgName = new Telerik.Windows.Documents.Model.Span();
orgName.FontSize = 10;
orgName.Text = relatedOrganisationObj.related_organization_name + "\r\n";
paragraph.Inlines.Add(orgName);
Telerik.Windows.Documents.Model.Span addLine1 = new Telerik.Windows.Documents.Model.Span();
addLine1.FontSize = 10;
addLine1.Text = relatedOrganisationObj.address_line_1 + "\r\n";
paragraph.Inlines.Add(addLine1);
if (relatedOrganisationObj.address_line_2 != null)
{
Telerik.Windows.Documents.Model.Span addLine2 = new Telerik.Windows.Documents.Model.Span();
addLine2.FontSize = 10;
addLine2.Text = relatedOrganisationObj.address_line_2 + "\r\n";
paragraph.Inlines.Add(addLine2);
}
if (relatedOrganisationObj.city != null)
{
Telerik.Windows.Documents.Model.Span city = new Telerik.Windows.Documents.Model.Span();
city.FontSize = 10;
city.Text = relatedOrganisationObj.city +" " + relatedOrganisationObj.state_code + "\r\n";
paragraph.Inlines.Add(city);
}
if (relatedOrganisationObj.zip_code != null)
{
Telerik.Windows.Documents.Model.Span zipCode = new Telerik.Windows.Documents.Model.Span();
zipCode.FontSize = 10;
zipCode.Text = relatedOrganisationObj.zip_code + "\r\n";
paragraph.Inlines.Add(zipCode);
}
//End of Build Too Address
Telerik.Windows.Documents.Model.Span spanFrom = new Telerik.Windows.Documents.Model.Span();
spanFrom.FontSize = 10;
spanFrom.Text = "From," + "\r\n";
paragraph.Inlines.Add(spanFrom);
Telerik.Windows.Documents.Model.Span docName = new Telerik.Windows.Documents.Model.Span();
docName.FontSize = 10;
docName.Text = "Dr." + App.global_user.first_name + App.global_user.last_name + "\r\n";
paragraph.Inlines.Add(docName);
Telerik.Windows.Documents.Model.Span orgName2 = new Telerik.Windows.Documents.Model.Span();
orgName2.FontSize = 10;
orgName2.Text = facilityObj.facility_name + "\r\n";
paragraph.Inlines.Add(orgName2);
Telerik.Windows.Documents.Model.Span addLine12 = new Telerik.Windows.Documents.Model.Span();
addLine12.FontSize = 10;
addLine12.Text = facilityObj.address_line_1 + "\r\n";
paragraph.Inlines.Add(addLine12);
if (facilityObj.address_line_2 != null)
{
Telerik.Windows.Documents.Model.Span addLine22 = new Telerik.Windows.Documents.Model.Span();
addLine22.FontSize = 10;
addLine22.Text = facilityObj.address_line_2 + "\r\n";
paragraph.Inlines.Add(addLine22);
}
if (facilityObj.City != null)
{
Telerik.Windows.Documents.Model.Span city2 = new Telerik.Windows.Documents.Model.Span();
city2.FontSize = 10;
city2.Text = facilityObj.City + "\r\n";
paragraph.Inlines.Add(city2);
}
if (facilityObj.state_code != null)
{
Telerik.Windows.Documents.Model.Span stateCode2 = new Telerik.Windows.Documents.Model.Span();
stateCode2.FontSize = 10;
stateCode2.Text = facilityObj.state_code + "\r\n";
paragraph.Inlines.Add(stateCode2);
}
if (facilityObj.zip_code != null)
{
Telerik.Windows.Documents.Model.Span zipCode2 = new Telerik.Windows.Documents.Model.Span();
zipCode2.FontSize = 10;
zipCode2.Text = facilityObj.zip_code + "\r\n";
paragraph.Inlines.Add(zipCode2);
}
radRichTextBox.Document = doc;
You can not have carriage returns ("\r") and symbols for new line ("\n") in the Text of a Span. The combination "\r\n" is used to separate different paragraphs and the document structure becomes invalid when you add them to the text of spans.
In order to achieve the result you are looking for, you should create different paragraphs and add them to the Section's Blocks property instead of adding them as spans to one paragraph.
Here is a sample code illustrating the approach:
private
RadDocument BuildDocument()
{
RadDocument doc =
new
RadDocument();
doc.LayoutMode = DocumentLayoutMode.Paged;
Telerik.Windows.Documents.Model.Section section =
new
Telerik.Windows.Documents.Model.Section();
doc.Sections.Add(section);
doc.SectionDefaultPageMargin =
new
Telerik.Windows.Documents.Layout.Padding(50, 50, 50, 50);
///Build To Address
Telerik.Windows.Documents.Model.Paragraph paragraphTo = CreateParagraphWithText(
"To,"
);
section.Blocks.Add(paragraphTo);
Telerik.Windows.Documents.Model.Paragraph paragraphRefPhy = CreateParagraphWithText(referringPhysician);
section.Blocks.Add(paragraphRefPhy);
Telerik.Windows.Documents.Model.Paragraph orgName = CreateParagraphWithText(relatedOrganisationObj.related_organization_name);
section.Blocks.Add(orgName);
Telerik.Windows.Documents.Model.Paragraph addLine1 = CreateParagraphWithText(relatedOrganisationObj.address_line_1);
section.Blocks.Add(addLine1);
if
(relatedOrganisationObj.address_line_2 !=
null
)
{
Telerik.Windows.Documents.Model.Paragraph addLine2 = CreateParagraphWithText(relatedOrganisationObj.address_line_2);
section.Blocks.Add(addLine2);
}
if
(relatedOrganisationObj.city !=
null
)
{
Telerik.Windows.Documents.Model.Paragraph city = CreateParagraphWithText(relatedOrganisationObj.city +
" "
+ relatedOrganisationObj.state_code);
section.Blocks.Add(city);
}
//...
return
doc;
}
private
Telerik.Windows.Documents.Model.Paragraph CreateParagraphWithText(
string
text,
double
fontSize = 10)
{
Telerik.Windows.Documents.Model.Paragraph paragraph =
new
Telerik.Windows.Documents.Model.Paragraph();
Telerik.Windows.Documents.Model.Span span =
new
Telerik.Windows.Documents.Model.Span();
span.Text = text;
span.FontSize = fontSize;
paragraph.Inlines.Add(span);
return
paragraph;
}
I hope that helps. All the best,
Iva
the Telerik team
Tom