Linq obtiene resultados diferentes de SL 4 y SL 5
Frecuentes
Visto 104 veces
1
Tengo un texto enriquecido en la aplicación SL. Quiero obtener texto sin formato, así que convierto texto enriquecido con formato a xml, luego trato de deshacerme de todas las marcas de formato. Está bien cuando ejecuto la aplicación con SL4. pero no funciona para SL 5.
Aquí están los datos en formato enriquecido:
<Section xml:space="preserve" HasTrailingParagraphBreakOnPaste="False" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Paragraph FontSize="20" FontFamily="Calibri" 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 FontSize="20" FontFamily="Calibri" Foreground="#FFFF0000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal">Hello ddd </Run>
</Paragraph>
</Section>
Uso este código para eliminar el marcado (el valor está por encima de los datos de entrada):
XDocument xmlRichText = XDocument.Parse(value.ToString());
var q = from c in xmlRichText.Descendants(xamlPresentationNamespace + "Run")
select (string)c.Attribute("Text");
foreach (string text in q)
result += text + " ";
¿Cómo hacer que funcione tanto para SL 4 como para SL5?
1 Respuestas
2
No veo ningún atributo llamado "Texto". Si necesita el valor "Hola ddd", puede hacer esto:
XNamespace ns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
var path = "...\file.xml";
using(var stream = File.Open(path, FileMode.Open))
{
var q = XDocument.Load(stream).Descendants(ns + "Run").Select (d => d.Value);
var result = string.Join(" ", q);
Debug.WriteLine(result);
}
Esto funciona en LINQPad, pero no lo he probado en SL4 o SL5.
contestado el 22 de mayo de 12 a las 21:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas linq silverlight-4.0 linq-to-xml silverlight-5.0 or haz tu propia pregunta.