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

ChangeStyleName crashes if Track Changes is enabled

1 Answer 51 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 08 Aug 2016, 11:46 AM

Hi,

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

System.ArgumentNullException
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;
else
{
    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.

 

Regards,

Daniel

 

 

1 Answer, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 11 Aug 2016, 10:55 AM
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  I am unable to suggest you an appropriate approach to work around the issue.

Regards,
Tanya
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
RichTextBox
Asked by
Daniel
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Share this question
or