Hi all,
I am working on a WPF application using Telerik UI for Silverlight (http://demos.telerik.com/silverlight/#RichTextBox/TelerikEditor)
and coded in C# .NET.
I took the code of the previous link and set it
up to fit my needs.
I am now facing to an issue : How to directly load by
coding a .rtf document into a RadRichTextBox ?
I tried two ways :
RtfFormatProvider provider = new RtfFormatProvider();
RadDocument = null;
using (FileStream stream = new FileStream(FileName,
FileMode.Open))
{
document = provider.Import(stream);
}
DocumentFragment docFrag = new DocumentFragment(document);
radRichTextBox.InsertFragment(docFrag);
-> But that way causes an error because the “Import” method returns a
RadFlowDocument whereas I am expecting a RadDocument.
RtfFormatProvider provider = new RtfFormatProvider();
Telerik.Windows.Documents.Model.Section section = new Telerik.Windows.Documents.Model.Section();
Telerik.Windows.Documents.Model.Paragraph paragraph = new
Telerik.Windows.Documents.Model.Paragraph();
string line;
using (StreamReader stream = new StreamReader(FileName))
{
while ((line = stream.ReadLine()) != null)
{
Telerik.Windows.Documents.Model.Span span = new
Telerik.Windows.Documents.Model.Span(line);
try
{
paragraph.Inlines.Add(span);
}
catch(Exception e)
{
string x = e.StackTrace;
}
}
}
section.Blocks.Add(paragraph);
radRichTextBox.Document.Sections.Add(section);
-> There, even if there is no error, the problem is that nothing is shown
in the editor.
The most strange is that, when I run the program without trying to load any document at the opening, the window opens perfectly and all the buttons react with the right behavior (see attachment “RadRichTextBoxEditor.png”) but I am not allowed to load a .rtf document whereas it is allowed on the link provided at the top of this topic. (see attachment “notSupportedRTF.png”)
Any help or tip will be much appreciated :)