J'ai utilisé une solution laide jusqu'à présent, utilisez un FlowDocument pour changer le format de rtf en xaml. Ensuite, supprimez les attributs non acceptés dans la boîte SL4 richtext, les codes comme ci-dessous. Ça marche mais je déteste ça. Je veux savoir s'il existe une meilleure solution.
string xaml = String.Empty;
FlowDocument doc = new FlowDocument();
TextRange range = new TextRange(doc.ContentStart, doc.ContentEnd);
using (MemoryStream ms = new MemoryStream())
{
using(StreamWriter sw = new StreamWriter(ms))
{
sw.Write(from);
sw.Flush();
ms.Seek(0, SeekOrigin.Begin);
range.Load(ms, DataFormats.Rtf);
}
}
using(MemoryStream ms = new MemoryStream())
{
range = new TextRange(doc.ContentStart, doc.ContentEnd);
range.Save(ms, DataFormats.Xaml);
ms.Seek(0, SeekOrigin.Begin);
using (StreamReader sr = new StreamReader(ms))
{
xaml = sr.ReadToEnd();
}
}
// remove all attribuites in section and remove attribute margin
int start = xaml.IndexOf("<Section");
int stop = xaml.IndexOf(">") + 1;
string section = xaml.Substring(start, stop);
xaml = xaml.Replace(section, "<Section xml:space=\"preserve\" HasTrailingParagraphBreakOnPaste=\"False\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">");
xaml = xaml.Replace("Margin=\"0,0,0,0\"", String.Empty);
Hmm ... voyant que Silverlight ne supporte pas FlowDocument à tout cela est un peu confus. – AnthonyWJones
oui, vous avez raison. Silverlight ne supporte pas Flowdocument, ce que j'ai fait est d'utiliser FlowDocument dans un webservice, puis silverlight peut parler au webservice – fresky