The default styles are not copied when using the CreateDocumentFromSelection method.
Workaround: Manually copy the styles:
var document = radRichTextBox.Document.Selection.CreateDocumentFromSelection();
document.StyleRepository.Clear();
foreach (var item in radRichTextBox.Document.StyleRepository)
{
var style = new StyleDefinition(item);
document.StyleRepository.Add(style);
}
Try the following scenario:
Hi,
This issue was referenced all the way back in 2017 in this post for Win Forms, but it appears it was never actually resolved; only a workaround was provided. I don't think this workaround will work for me, however, because I am binding to the RtfDataProvider in xaml and therefore it makes the changes to the document string before I am able to do a manual replacement of "rtf1" where it only had "rtf" for the version tag before. While changing the tag after the fact will fix the issue of it not being recognized in the other software we use, it still causes bloat because of the fact that it most cases it over triples the amount of raw text in the returned string when the textbox does not properly apply the rtf version tag.
Below is an example of the greatly enlarged amount of data before and after this error occurs:
"S11111^A^1^","{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial; } }\viewkind4\uc1 \f0\fs20 Measurements: \par \tab Neck to Fundus \tab \tab 1.5 cm \par \tab Diameter at Fundus \tab \tab 3.0 cm \par \tab Color \tab \tab \tab \tab Green-Tan \par \tab Wall Thickness \tab \tab 1.0 cm \par \tab Mucosa \tab \tab \tab Velvety \par \par No Cholesterolosis Is Identified \par \par No Bile Identified \par \par No Gallstones Are Identified \par \par Summary of Sections: \par \tab Received in Bag and Formalin. The cystic duct margin and representative sections of gallbladder fundus and body are submitted in 1 cassette. \par \par KG/sjh }"^""$$$"
"S11111^A^1^","{\rtf\ansi\ansicpg1252\uc1\deff0\deflang1033{\fonttbl{\f0 Verdana;}{\f1 Arial;}}{\colortbl\red0\green0\blue0 ;}{\*\defchp\ltrch\f0\fs20\i0\b0\strike0\cf0\ulc0\ulnone}{\*\defpap\sl276\slmult1\ql\sa180\ltrpar}{\stylesheet{\s0\sqformat\spriority0\ltrch\f0\fs20\i0\b0\strike0\cf0\ulc0\ulnone\sl276\slmult1\ql\sa180\ltrpar Normal;}{\*\ts2\tsrowd\spriority59\trbrdrt\brdrnone\trbrdrb\brdrnone\trbrdrl\brdrnone\trbrdrr\brdrnone\trbrdrh\brdrnone\trbrdrv\brdrnone\trgaph0\trpaddl75\trpaddr75\trpaddt0\trpaddb0\clpadft3\clpadt0\clpadfr3\clpadr0\clpadfl3\clpadl0\clpadfb3\clpadb0\tsvertalt\ltrch\f0\fs20\i0\b0\strike0\cf0\ulc0\ulnone\sl276\slmult1\ql\sa180\ltrpar Table Normal;}}\nouicompat\viewkind4\paperw12240\paperh15840\margl1425\margr1425\margt1425\margb1425\deftab720\sectd\pgwsxn12240\pghsxn15840\marglsxn1425\margrsxn1425\margtsxn1425\margbsxn1425\headery720\footery720\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone Measurements: }{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone \tab Neck to Fundus \tab \tab 1.6 cm }{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone \tab Diameter at Fundus \tab \tab 3.0 cm }{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone \tab Color \tab \tab \tab \tab Green-Tan }{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone \tab Wall Thickness \tab \tab 1.0 cm }{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone \tab Mucosa \tab \tab \tab Velvety }{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone }{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone No Cholesterolosis Is Identified }{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone No Bile Identified }{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone No Gallstones Are Identified }{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone Summary of Sections: }{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone \tab Received in Bag and Formalin. The cystic duct margin and representative sections of gallbladder fundus and body are submitted in 1 cassette. }{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl240\slmult1\ql\ltrpar{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone KG/sjh }{\ltrch\f1\fs20\i0\b0\strike0\cf0\ulc0\ulnone\par}}"^""$$$"
If there is a way that I can use the workaround in that post to prevent this bloating of the data while still using my current setup with bindings, I would be happy to do so, but as it is I don't think that's the case. It seems like this is clearly a bug and something that should have a real fix on the control and not a workaround after all this time, but if that's not the case and it was left as is for a reason, I'd be happy to hear that reason.
Thanks in advance for the help.
In the Track Change mode, try to insert several images using standard InsertPictureCommand (or even Editor.InsertImage()) double enter and then again. Or insert text between already inserted images.
The error could be also observed when accepting all changes.
<p data-telerik-id="Paragraph637567542110611335">
<span data-telerik-id="Span637567542110611345">
Test
</span>
</p>
public class HiResDateTime
{
private static long lastTimeStamp = DateTime.UtcNow.Ticks;
private static readonly Regex digitsOnly = new Regex(@"[^\d]");
public static long UtcNowTicks
{
get
{
long original, newValue;
do
{
original = lastTimeStamp;
long now = DateTime.UtcNow.Ticks;
newValue = Math.Max(now, original + 1);
} while (Interlocked.CompareExchange
(ref lastTimeStamp, newValue, original) != original);
return newValue;
}
}
public static string UtcNowTicksString => digitsOnly.Replace(UtcNowTicks.ToString(), "");
}
The pasted content is not formatted properly, resulting in an InvalidOperationException("'Token EndElement in state EndRootElement would result in an invalid XML document. Make sure that the ConformanceLevel setting is set to ConformanceLevel.Fragment or ConformanceLevel.Auto if you want to write an XML fragment. ') when saving the content to DOCX.
Steps to reproduce:
Workaround: intercept the table paste and add an empty paragraph as the first element of the document before the table.
Another case:
Steps to reproduce: