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

Indent not working as expected

2 Answers 54 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
zhivko.zhelezov
Top achievements
Rank 1
zhivko.zhelezov asked on 12 Aug 2015, 08:00 AM

Hello,

  I have a question about Richtextbox DocumentRuler.

The case is as follows..I insert  a table with several rows and columns into my document then insert an InlineUIContainer with a custom control in some table cell.

When I try to change the left/right indent of the inserted InlineUIContainer element a null reference exception is thrown.

 

Here are the exception details:
{System.NullReferenceException: Object reference not set to an instance of an object.
   at Telerik.Windows.Documents.Commands.Styles.Paragraphs.ChangeParagraphStyleCommandBase`2.PreserveStateBeforeExecute(TContext context)
   at Telerik.Windows.Documents.Commands.UndoableDocumentCommandBase`1.OnExecuting(DocumentCommandContextBase context)
   at Telerik.Windows.Documents.Commands.DocumentCommandBase`1.Execute(DocumentCommandContextBase context)
   at Telerik.Windows.Documents.Model.RadDocumentEditor.ChangeParagraphLeftIndent(Double leftIndent)
   at Telerik.Windows.Controls.RadRichTextBox.ChangeParagraphLeftIndent(Double leftIndent)
   at Telerik.Windows.Controls.RichTextBoxUI.RadRichTextBoxRulerController.SetSeparatorFirstLineIndentAndHangingIndent(Double firstLineIndent, Double hangingIndent)
   at Telerik.Windows.Controls.RichTextBoxUI.DocumentRulerBase.LeftIndent_DragCompleted(Object sender, DragCompletedEventArgs e)
   at Telerik.Windows.Controls.RichTextBoxUI.RulerThumb.RaiseDragCompleted(Boolean canceled)
   at Telerik.Windows.Controls.RichTextBoxUI.RulerThumb.OnLostMouseCapture(MouseEventArgs e)
   at System.Windows.Controls.Control.OnLostMouseCapture(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)}

 

Here is the code of InlineUIContainer addition:

 

            var container = new InlineUIContainer(instrumentItem, uiSize);

            DocumentPosition position = editor.Document.CaretPosition;
            Paragraph paragraph = new Paragraph();
            container.Width = uiSize.Width;
            container.Height = uiSize.Height;
            paragraph.Inlines.Add(container);

            var paragraphBox = position.GetCurrentParagraphBox();

            if (paragraphBox != null)
            {
                editor.Document.Sections.First.Blocks.AddAfter(paragraphBox.AssociatedParagraph, paragraph);
            }
            else
            {
                editor.Document.Sections.First.Blocks.Add(paragraph);
            }

            editor.UpdateEditorLayout();

 

 

Thanks!

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Petya
Telerik team
answered on 14 Aug 2015, 03:41 PM
Hi Zhivko,

I wasn't able to replicate the error and am not sure what version of the suite you're using, but am presuming this is related to the approach you're suing to add the InlineUIContainer in the document.

In short, modifying the collections of document elements of a measured document (one that has its size and layout calculated) is not recommended and instead you can use the methods of RadRichTextBox or RadDocumentEditor. Could you try adding the control with the InsertInline() method of RadRichTextBox and see if the issue persists?

Regards,
Petya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
zhivko.zhelezov
Top achievements
Rank 1
answered on 24 Aug 2015, 10:48 AM

Hello,

  It helped for me when using InsertInline(..) method.

Thank you for your answer!

Tags
RichTextBox
Asked by
zhivko.zhelezov
Top achievements
Rank 1
Answers by
Petya
Telerik team
zhivko.zhelezov
Top achievements
Rank 1
Share this question
or