This is a migrated thread and some comments may be shown as answers.

Text properties are not being saved

1 Answer 47 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Wayne
Top achievements
Rank 1
Wayne asked on 15 Dec 2011, 03:50 PM

Hi,

When I set the text properties say to Bold in my RTB these are not saved to the DB. So when I re-load the RTB from the DB I get the text but not in Bold as I saved it.

Below is the code how I save and re-load the data from and to my RTB.

 

Fist my RTB.

<rad:RadRichTextBox  Name="RTBReceiptFooter" IsReadOnly="False" DocumentContentChanged="TXTPropertyChanged_ReceiptFooter" DocumentInheritsDefaultStyleSettings="True" ShowFormattingSymbols="True" />

Here I grab the text from the RTB in the xaml.cs:

//Export Text

private void TXTPropertyChanged_ReceiptFooter(object sender, EventArgs e)

{

    IDocumentFormatProvider exporter = new TxtFormatProvider();

                using (MemoryStream stream = new MemoryStream())

                {

                    exporter.Export(this.RTBReceiptFooter.Document, stream);

                    stream.Seek(0, SeekOrigin.Begin);

                    StreamReader reader = new StreamReader(stream);

                   

                     _viewModel.MyText = reader.ReadToEnd();

                }

}

Here I get the text from the db in the xaml.cs:

 

_LongDiscriptionSub = _viewModel.MyText;

public void ProvideSubText()

{

    IDocumentFormatProvider provider = new TxtFormatProvider();

            using (var stream = new MemoryStream())

            {

                var writer = new StreamWriter(stream);

                writer.Write(_LongDiscriptionSub);

                writer.Flush();

                stream.Seek(0, SeekOrigin.Begin);

                RTBReceiptFooter.Document = provider.Import(stream);

            }

}
Thanky very much

1 Answer, 1 is accepted

Sort by
0
Mike
Telerik team
answered on 20 Dec 2011, 12:51 PM
Hi Wayne,

We noticed you are using TxtFormatProvider to persist RadRichTextBox document. TxtFormatProvider uses txt as underlying format thus it would not persist the rich-text content.

You should use XamlFormatProvider, which on the other hand will persist all document structure (including rich-text formatting, headers/footer, comments, styles and so on) as a Xaml string.

XamlFormatProvider also has APIs that would help you load and save the document directly to a string - to use them you should not cast the provider instance to IDocumentFormatProvider.

Regards,
Mike
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Wayne
Top achievements
Rank 1
Answers by
Mike
Telerik team
Share this question
or