Hi Everyone,
The following code is displaying correctly in a RichTextBox but when I save it and reload it, the InlineUIContainer item is missing (other text and formatting is displayed as normal):
Line line = new Line {X1 = 0yed Y1 = 0, X2 = 1, Y2 = 0, Stroke = new SolidColorBrush(Colors.Gray), Stretch = Stretch.Fill}; InlineUIContainer container = new InlineUIContainer(line, rtNotes.CaretPosition.GetInsertionPosition(LogicalDirection.Forward)); rtNotes.CaretPosition.Paragraph.Inlines.Add(container);
I am saving the FlowDocument as RTF to a string (Memo) column in a database with this code:
internal static string SaveRTF(RichTextBox richTextBox) { using (MemoryStream stream = new MemoryStream()) { TextRange range = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd); range.Save(stream, DataFormats.Rtf); return ASCIIEncoding.Default.GetString(stream.ToArray()); } }And loading it with this code:
internal static void LoadRTF(RichTextBox richTextBox, string rtf) { if (rtf.Length == 0) return; TextRange range = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd); using (MemoryStream stream = new MemoryStream()) { using (StreamWriter writer = new StreamWriter(stream)) { writer.Write(rtf); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); range.Load(stream, DataFormats.Rtf); } } }
I've examined the FlowDocument XAML before it's saved and the InlineUIContainer seems to be missing. Does anyone know what I'm doing wrong?
Thanks.