///<summary> /// convert the string "from" from sourceFormat to targetFormat ///</summary> ///<param name="from"></param> ///<param name="sourceFormat">System.Windows.DataFormats.Rtf</param> ///<param name="targetFormat">System.Windows.DataFormats.Xaml </param> ///<returns></returns> privatestringconvertFormat(stringfrom, string sourceFormat, string targetFormat) { string xaml = String.Empty; System.Windows.Documents.FlowDocument doc = new System.Windows.Documents.FlowDocument(); System.Windows.Documents.TextRange range = new System.Windows.Documents.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, sourceFormat); } }
using (MemoryStream ms = new MemoryStream()) { range = new System.Windows.Documents.TextRange(doc.ContentStart, doc.ContentEnd);
range.Save(ms, targetFormat); ms.Seek(0, SeekOrigin.Begin); using (StreamReader sr = new StreamReader(ms)) { xaml = sr.ReadToEnd(); } }
// remove all attribuites in section and remove attribute margin if (targetFormat.Equals(System.Windows.DataFormats.Xaml)) { int start = xaml.IndexOf("<Section"); int stop = xaml.IndexOf(">") + 1;