我想以 XamlPackage 格式将 RichTextBox 的内容保存到 varbinary(= 字节数组)。我需要有关如何操作的技术建议。
我实际上需要知道如何在 FlowDocument 和字节数组之间进行转换。
是否甚至建议将其存储为 varbinary,或者这是一个坏主意?
更新
代码片段:
///Load
byte[] document = GetDocumentFromDataBase();
RickTextBox tb = new RickTextBox();
TextRange tr = new TextRange(tb.Document.ContentStart, tb.Document.ContentEnd)
tr.Load(--------------------------) //Load from the byte array.
///Save
int maxAllowed = 1024;
byte[] document;
RichTextBox tb = new RichTextBox();
//User entered text and designs in the rich text
TextRange tr = new TextRange(tb.Document.ContentStart, tb.Document.ContentEnd)
tr.Save(--------------------------) //Save to byte array
if (document.Length > maxAllowed)
{
MessageBox.Show((document.Length - maxAllowed) + " Exceeding limit.");
return;
}
SaveToDataBase();
TextRange