FlowDocument document = rtt.Document; System.IO.Stream ms = new System.IO.MemoryStream(); System.Windows.Markup.XamlWriter.Save(document, ms); byte[] data = new byte[ms.Length]; ms.Position = 0; ms.Read(data, 0, data.Length); ms.Close(); File.WriteAllBytes(THE PATH, data);By the code above, I put the content of a richtextbox(named as rtt)into a stream, then save this stream into a .rtf file.
Since I nested a small richtextbox into the big richtexbox(named as rtt) by BlockUIContainer, so I think I can not use richTextBox.Document.ContentStart,
richTextBox.Document.ContentEnd, (i suppose this is only suitable for pure text?) I tried to convert the content in richtextbox into binary stream.
But the problem is, in the saved file, the content from the richtextbox is shown in below format:
<FlowDocument PagePadding="5,0,5,0" AllowDrop="True" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Paragraph>RichTextBoxggg<Run xml:lang="en" xml:space="preserve"> it is just a test!!!!</Run></Paragraph><BlockUIContainer><RichTextBox IsReadOnly="True" Name="rtb2"><FlowDocument PagePadding="5,0,5,0" AllowDrop="True"><Paragraph>sdlf</Paragraph></FlowDocument></RichTextBox></BlockUIContainer></FlowDocument>
It is shown as xaml format, but i want it shown as the format in WPF (the view when i design in WPF, ),
So How can I convert the content of a richtexbox to binary stream, and then save it as a rtf file in a disk (and show as the wpf view, not the xaml format)