Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Problem with saving InlineUIContainer items in a FlowDocument

$
0
0

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.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>