
<RichTextBox x:name="rtbControl" Height="auto" ContentChanged="rtbControl_ContentChanged" />
随着数据的更改,我将其捕获到局部变量中,如下所示:
private voID rtbControl_ContentChanged(object sender,ContentChangedEventArgs e) { RichTextContent = rtbControl.Xaml; } 一切都有效.但是,如果我输入几个单词并检查<段落>加价,真是太棒了!下面是一个片段.有没有办法在标记中没有所有的排版内容?它为什么存在并且需要它?有没有办法删除它?
<Section xml:space="preserve" HasTrailingParagraphBreakOnPaste="False" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Paragraph FontSize="11" FontFamily="Segoe UI" Foreground="#FF000000" FontWeight="normal" FontStyle="normal" FontStretch="normal" CharacterSpacing="0" Typography.AnnotationAlternates="0" Typography.EastAsianExpertForms="False" Typography.EastAsianLanguage="normal" Typography.EastAsianWIDths="normal" Typography.Standardligatures="True" Typography.Contextualligatures="True" Typography.discretionaryligatures="False" Typography.Historicalligatures="False" Typography.StandardSwashes="0" Typography.ContextualSwashes="0" Typography.ContextualAlternates="True" Typography.StyListicAlternates="0" Typography.StyListicSet1="False" Typography.StyListicSet2="False" Typography.StyListicSet3="False" Typography.StyListicSet4="False" Typography.StyListicSet5="False" Typography.StyListicSet6="False" Typography.StyListicSet7="False" Typography.StyListicSet8="False" Typography.StyListicSet9="False" Typography.StyListicSet10="False" Typography.StyListicSet11="False" Typography.StyListicSet12="False" Typography.StyListicSet13="False" Typography.StyListicSet14="False" Typography.StyListicSet15="False" Typography.StyListicSet16="False" Typography.StyListicSet17="False" Typography.StyListicSet18="False" Typography.StyListicSet19="False" Typography.StyListicSet20="False" Typography.CAPItals="normal" Typography.CAPItalSpacing="False" Typography.Kerning="True" Typography.CaseSensitiveForms="False" Typography.HistoricalForms="False" Typography.Fraction="normal" Typography.NumeralStyle="normal" Typography.NumeralAlignment="normal" Typography.SlashedZero="False" Typography.MathematicalGreek="False" Typography.Variants="normal" Textoptions.TextHintingMode="Fixed" Textoptions.textformattingMode="IDeal" Textoptions.TextRenderingMode="auto" TextAlignment="left" lineHeight="0" linestackingStrategy="MaxHeight"><Run>was it a </Run><Run Textdecorations="Underline">bad </Run><Run>blah? or </Run></Paragraph></section>解决方法 我以为我会分享我的解决方案来帮助别人……它已经存在好几个月了,我还没有看到任何不良副作用.
我创建了一些扩展方法来帮助删除Typography属性.
public static class RichTextBoxExtensions { // <summary> /// Removes any xml tag with the prefix given from a string /// </summary> /// <param name="XMLString"></param> /// <param name="TagPrefix"></param> /// <returns></returns> public static string RemoveXMLAttributesFromNode(this string XMLString,string prefix) { //Match [Prefix][any number of Not =][=]["][any number of Not "]["][ ] <-must have space!!! string replace = prefix + "[^\=]*=\"[^\"]*\" "; return Regex.Replace(XMLString,replace,string.Empty); } /// <summary> /// Removes any xml tag with prefixed by an element in unWanted /// </summary> /// <param name="XMLString"></param> /// <param name="TagPrefix"></param> /// <returns></returns> public static string RemoveXMLAttributesFromNode(this string XMLString,List<string> unWanted) { foreach (string prefix in unWanted) { //Match [Prefix][any number of Not =][=]["][any number of Not "]["][ ] <-must have space!!! string replace = prefix + "[^\=]*=\"[^\"]*\" "; XMLString = Regex.Replace(XMLString,string.Empty); } return XMLString; } 接下来,在我将字符串保存到数据库之前,我删除了不良属性,如下所示:
List<string> badAttributes = new List<string>(); badAttributes.Add("Typography"); var ffText = ffi.FreeFormText == null ? null : ffi.FreeFormText.RemoveXMLAttributesFromNode(badAttributes); 在删除这些属性后重新渲染RTF时,我没有看到任何问题.希望这个解决方
总结以上是内存溢出为你收集整理的Silverlight RichTextBox中的XAML标记大小过多全部内容,希望文章能够帮你解决Silverlight RichTextBox中的XAML标记大小过多所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)