I'm populating the document from strings to show it in RichTextBox. The code is very simple:
RadDocument document = new RadDocument();
Span span = new Span() { FontSize = 14, FontWeight = FontWeights.Bold };
span.Text = "123";
document.InsertInline(span);
But I'm getting the following exception:
System.NullReferenceException was caught
StackTrace:
в Telerik.Windows.Documents.DocumentStructure.DocumentStructureCollection.MergeContainers(LayoutBox fromBox)
в Telerik.Windows.Documents.Model.RadDocument.InsertFragmentInternal(DocumentPosition position, DocumentFragment fragment)
в Telerik.Windows.Documents.Model.RadDocument.InsertFragment(DocumentFragment fragment, DocumentPosition position)
в Telerik.Windows.Documents.Model.RadDocument.InsertInline(Inline inline, DocumentPosition position)
в Telerik.Windows.Documents.Model.RadDocument.InsertInline(Inline inline)
в QESE.QFV.UI.Grid.Controls.HelpPopup.Populate(String title, HelpTexts texts)
InnerException:
Why?
---
Mike
8 Answers, 1 is accepted
RadDocument document = new RadDocument();
Section section = new Section();
Paragraph paragraph = new Paragraph();
section.Blocks.Add(paragraph);
document.Sections.Add(section);
Span span = new Span() { FontSize = 14, FontWeight = FontWeights.Bold };
span.Text = "123";
document.InsertInline(span);
the exception callstack slightly changes
System.NullReferenceException was caught
Message=В экземпляре объекта не задана ссылка на объект.
StackTrace:
в Telerik.Windows.Documents.Model.RadDocument.InsertInternal(String text, Span newSpanInstance, Span selectedSpanStyle, DocumentPosition positionToInsert)
в Telerik.Windows.Documents.Model.RadDocument.InsertInternal(Span span, DocumentPosition positionToInsert)
в Telerik.Windows.Documents.Model.RadDocument.InsertDocumentElementInternal(DocumentPosition position, DocumentElement elementToCopy)
в Telerik.Windows.Documents.Model.RadDocument.InsertFragmentInternal(DocumentPosition position, DocumentFragment fragment)
в Telerik.Windows.Documents.Model.RadDocument.InsertFragment(DocumentFragment fragment, DocumentPosition position)
в Telerik.Windows.Documents.Model.RadDocument.InsertInline(Inline inline, DocumentPosition position)
в Telerik.Windows.Documents.Model.RadDocument.InsertInline(Inline inline)
в QESE.QFV.UI.Grid.Controls.HelpPopup.Populate(String title, HelpTexts texts)
InnerException:
Since the issues Mike had encountered has been solved by upgrading to a later version, their cause is probably a different one.
Overall, when instantiating a RadDocument, a Section and Paragraphs manually, the Spans had to be added to the Inlines collection of the Paragraph instead of through the document's InsertInline method. This issue has been solved in the latest version of the controls.
In your scenario, InsertInline must work as expected. We'd be happy to address the particular problems you have met in the support ticket you opened.
Iva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
We have not been able to reproduce the issue with InsertInline in the first place.
Could you give us a code-snippet, or a demo which reproduces the issue, so that we can identify the cause and make sure to fix the problem if it is still present with the latest version of the controls - the service pack of Q2.
Iva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Overall, when instantiating a RadDocument, a Section and Paragraphs manually, the Spans had to be added to the Inlines collection of the Paragraph instead of through the document's InsertInline method. This issue has been solved in the latest version of the controls.
So my question was:
Does this work Document.InsertLines(span) now as stated above ? Which release?
or does this till only work against Paragraph objects
Let me elaborate a bit on the whole story behind the use of methods from the API and the programmatic building of RadDocuments.
The document has two states depending on if it has been measured or not. Some operations expect that the document has been measured, while others can only be performed on not measured documents. Manipulating the structure of the document explicitly (adding Inlines and Paragraphs to the Blocks and Inlines properties) can be performed on not measured documents only.
The document is measured by the Silverlight framework when shown in the editor. After that, you should use the methods from RadRichTextBox's API - InsertTable, InsertInline, InsertBookmark, etc. when you need to manipulate the content of the document. In previous versions of the control (before Q2 2011 Beta - 2011.2.623), methods from RadRichTextBox's and RadDocument's API could not be invoked on not-measure documents and explicit Measure and Arrange had to be invoked like this:
public
void
MeasureAndArrangeInDefaultSize(RadDocument document)
{
document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
document.Arrange(
new
RectangleF(PointF.Empty, document.DesiredSize));
}
Starting from the Q2 2011 Beta, this is no longer needed, as a similar method is invoked internally when an operation that requires that the document be measured is invoked.
Therefore, the code from Mike's snippet works fine in the versions from 2011.2.623 on. The version of the controls that Charles was using was also an older one that 2011.2.623.
I hope this answers your question. Regards,
Iva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>