Indent not working as expected

3 posts, 1 answers
  1. zhivko.zhelezov
    zhivko.zhelezov avatar
    31 posts
    Member since:
    May 2011

    Posted 12 Aug 2015 Link to this post


      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;

                var paragraphBox = position.GetCurrentParagraphBox();

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






  2. Answer
    Petya avatar
    973 posts

    Posted 14 Aug 2015 Link to this post

    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?

    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
  3. DevCraft R3 2016 release webinar banner
  4. zhivko.zhelezov
    zhivko.zhelezov avatar
    31 posts
    Member since:
    May 2011

    Posted 24 Aug 2015 Link to this post


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

    Thank you for your answer!

Back to Top