Display rich formatted text using WPF

I'm new to WPF so please bear with me if you find my question too primary. I want to get text from database and display this rich formatted document on my WPF app So far as I know I should use RICHTEXTBOX. So, my question is should I store rich formatted text to database and just display it to window(which ideally the displaying will keep its format) or should I just store lines of words without formatting and format it when I display it on the window. Which way should I do and HOW I do that. Specific answer with codes how to store or how to display would be greatly appreciated.


You can save the text (rtf format) in the database and load it in a RichTextBox with something like this:

    TextRange documentTextRange = new TextRange(RICHTEXTBOXNAME.Document.ContentStart, RICHTEXTBOXNAME.Document.ContentEnd);
    using (FileStream fs = File.Open(FILENAME, FileMode.Open))
    {
      documentTextRange.Load(fs, DataFormats.Rtf);
    }

In this example the content is stored in a file, but there is no big difference.

RichTextBox cannot be completely compatible with all rtf stuff, so if you create an rtf from another source you can encounter some graphic glitch.

链接地址: http://www.djcxy.com/p/50522.html

上一篇: 在WPF中显示文本时解析html标签

下一篇: 使用WPF显示丰富的格式化文本