ChangeStyleName crashes if Track Changes is enabled

2 posts, 0 answers
  1. Daniel
    Daniel avatar
    5 posts
    Member since:
    Apr 2015

    Posted 08 Aug Link to this post


    The line

    RtbEditor.ChangeStyleName(style.Name, true);

    Works perfectly when Track Changes is disabled. When it is enabled and there are tracked changes in the current paragraph, it works for the first time, but the next time it crashes with the exception

    Message "Value cannot be null.\r\nParameter name: owner"
       at Telerik.Windows.Documents.Model.Styles.DocumentElementPropertiesBase.SetDocumentElementOwner(DocumentElement owner)
       at Telerik.Windows.Documents.Model.Styles.ParagraphProperties.SetDocumentElementOwner(DocumentElement owner)
       at Telerik.Windows.Documents.Model.Styles.DocumentElementPropertiesBase..ctor(DocumentElement owner)
       at Telerik.Windows.Documents.Model.Styles.ParagraphProperties..ctor(DocumentElement owner)
       at Telerik.Windows.Documents.Model.Styles.ParagraphProperties.CreateInstance()
       at Telerik.Windows.Documents.Model.Styles.DocumentElementPropertiesBase.CopyPropertiesFrom(DocumentElementPropertiesBase fromProperties)
       at Telerik.Windows.Documents.Model.Styles.ParagraphProperties.CopyPropertiesFrom(DocumentElementPropertiesBase fromProperties)
       at Telerik.Windows.Documents.Commands.Styles.Paragraphs.ClearParagraphFormattingCommand.GetPropertyValue(Paragraph paragraph)
       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.ExecuteChangeStyleNameCommand(StyleType type, String styleName)
       at Telerik.Windows.Documents.Model.RadDocumentEditor.ChangeStyleName(String styleName, Boolean useLinkedStyle)
       at Telerik.Windows.Controls.RadRichTextBox.ChangeStyleName(String styleName, Boolean useLinkedStyle)


    I've made a workaround

    var spanstyle = style.LinkedStyle;
    var selection = RtbEditor.Document.Selection;
    if (!selection.IsEmpty)
        foreach (var span in selection.GetSelectedBoxes<SpanLayoutBox>().Select(x => x.AssociatedSpan).Distinct().ToList())
            span.Style = spanstyle;
        var paragraph = RtbEditor.Document.CaretPosition.GetCurrentParagraphBox().AssociatedParagraph;
        if (paragraph != null)
            foreach (var span in paragraph.Inlines.OfType<Span>().ToList())
                span.Style = spanstyle;


    And it seams to be working, but it is kind of hacking.


    I'm using version 2016.1.112.45 and haven't tested with the latest one as I don't have time to test if everything else works after the upgrade.






  2. Tanya
    Tanya avatar
    377 posts

    Posted 11 Aug Link to this post

    Hi Daniel,

    Thank you for bringing this to our attention.

    Indeed, I was able to reproduce the issue you are observing and logged it to our backlog. You could track its status through the related item in our public feedback portal. Your Telerik points are updated in appreciation for the report.

    I tested the workaround you have found as well but it seems that it isn't stable enough and works only for particular cases as I replicated the error after applying it. However, I am afraid that currently I am unable to suggest you an appropriate approach to work around the issue.

    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. DevCraft banner
Back to Top