Load richtextbox from memorystream. WPF/VB>NET

Posted by Peter on Stack Overflow See other posts from Stack Overflow or by Peter
Published on 2010-04-16T01:07:03Z Indexed on 2010/04/16 1:13 UTC
Read the original article Hit count: 747

Filed under:
|

Hi,

I have some trouble with loading a richtextbox from a memorystream.

I have some data in a database table stored as a byte array, I convert it to a string and load it into a memorystream and then I want to load that memory stream in the richtextbox. The application breaks on

Dim tr As New TextRange(rtbTemplate.Document.ContentStart, rtbTemplate.Document.ContentEnd)

though.

Code for getting the data from the database

    Dim TemplateData As Byte() = TemplateDataTableInstance.Rows(0).Item("TemplateData")
    Dim strTemplateData As String
    Dim enc As New System.Text.UTF8Encoding()
    strTemplateData = enc.GetString(TemplateData)

' I put a messagebox here to check if I get the data I want and I do

Now, how do I sort out the rest? I have

    Dim strDataFormat As String = DataFormats.Rtf
    Using ms As New MemoryStream(strTemplateData)
        Dim tr As New TextRange(rtbTemplate.Document.ContentStart, rtbTemplate.Document.ContentEnd)
        tr.Load(ms, strDataFormat)
    End Using

and my richtextbox in xaml

        <RichTextBox x:Name="rtbLetter">
            <RichTextBox.Resources>
                <Style TargetType="{x:Type Paragraph}">
                    <Setter Property="Margin" Value="0"/>
                </Style>
            </RichTextBox.Resources>
            <FlowDocument FontSize="12" FontFamily="Times New Roman">
            </FlowDocument>
        </RichTextBox>

Any help is appreciated.

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about wpf