문제

RichTextBox의 컨텐츠를 XAMLPackage 형식으로 varbinary (= byte array)에 저장하고 싶습니다. 방법에 대한 기술 조언이 필요합니다.

실제로 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
도움이 되었습니까?

해결책

지금 내 예제를 찾을 수는 없지만 xamlreader 및 xamlwriter를 사용하여 문자열 안팎으로 문서를 가져올 수 있습니다. 거기에서 유니 코드 코딩, asciiencoding 또는 바이트 안팎으로 가져 오려는 인코더를 사용할 수 있습니다.

문자열에서 문서를 설정하기위한 나의 짧은 예 ... Docreader는 내 흐름 문서 리더입니다.

        private void SetDetails(string detailsString)
    {
        if (docReader == null)
            return;
        if (String.IsNullOrEmpty(detailsString))
        {
            this.docReader.Document = null;
            return;
        }
        using (
        StringReader stringReader = new StringReader(detailsString))
        {
            using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(stringReader))
            {
                this.docReader.Document = XamlReader.Load(reader) as FlowDocument;
            }
        }
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top