简体   繁体   中英

Save color state of letters in a RichTextBox in WPF

I have a richtextbox in WPF that allows you to change the text to different colors. Some letters might be red, some might be blue, some might be black, etc. When the user clicks save, it will save the text but not the colors. So when they come back to the page, they get all the correct text, but it all defaults to the color black.

How can I save the state of these colors so that when the user comes back to the page at a later time, the letters will still be the same colors as they left it?

Just save the whole text as a byte array, you don't need to remember echa letter's color. Then, next time, use this method to load the formated text:

rtfBox.Selection.Load(myStreamFromByteArray, DataFormats.Rtf);

http://msdn.microsoft.com/en-us/library/system.windows.documents.textrange.load.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM