Silverlight RichTextBox中的XAML标记大小过大

Silverlight RichTextBox中的XAML标记大小过大,silverlight,richtextbox,silverlight-5.0,Silverlight,Richtextbox,Silverlight 5.0,我在silverlight 5应用程序中有一个非常简单的RichTextBox控件 <RichTextBox x:Name="rtbControl" Height="Auto" ContentChanged="rtbControl_ContentChanged" /> 一切顺利。然而,如果我只键入几个单词并检查标记,它将是巨大的!下面是一个片段。有没有办法不让所有的排版内容都出现在标记中?它为什么在那里,需要它吗?有没有办法把它去掉 <Section xm

我在silverlight 5应用程序中有一个非常简单的RichTextBox控件

<RichTextBox x:Name="rtbControl" 
    Height="Auto" 
    ContentChanged="rtbControl_ContentChanged" />
一切顺利。然而,如果我只键入几个单词并检查
标记,它将是巨大的!下面是一个片段。有没有办法不让所有的排版内容都出现在标记中?它为什么在那里,需要它吗?有没有办法把它去掉

<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>

这是个坏消息吗
废话?或

我想我会分享我的解决方案来帮助他人。。。它已经存在好几个月了,我没有看到任何不良副作用

我创建了一些扩展方法来帮助删除排版属性

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, replace, string.Empty);
            }
            return XMLString;
        }
公共静态类RichTextBoxExtensions{
// 
///从字符串中删除任何带有给定前缀的xml标记
/// 
/// 
/// 
/// 
公共静态字符串RemoveXMLAttributesFromNode(此字符串为XMLString,字符串前缀)
{

//匹配[Prefix][anynumber of Not=][=][][“][any number of Not”][][“][]哇,太大了:(我认为持久化需要确保您获得准确的格式。您想做什么?也许您可以使用文本或选定的文本属性?请参阅此官方示例。我为用户提供了创建文档片段的能力,我需要为他们提供富文本格式功能。用户输入将推送到数据库。我确实需要现在,用户可以在3行中键入4个单词,并且已经有4000多个字符的文本。我看到了两种减少内容大小的方法:压缩和解析XML以删除段落和公司的所有默认属性。但是我没有看到内置解决方案,抱歉。
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, replace, string.Empty);
            }
            return XMLString;
        }
        List<string> badAttributes = new List<string>();
        badAttributes.Add("Typography");
        var ffText = ffi.FreeFormText == null ? null : ffi.FreeFormText.RemoveXMLAttributesFromNode(badAttributes);