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