Open RCP161 opened 5 years ago
Sure, that's something that you can do.
However, that really doesn't conform to the MVVM pattern as your view models should not be concerned with anything related to view. As an example, your view model should not care about alignment, style, content, and child content. Therefore, I don't believe it belongs in the main AvalonDock codebase, but is something you can do to extend RichTextBox if that is something you want to do.
Yeah, it was only an idea, in result, that the property already exists.
My Problem was, that I had a plain Text, that I want to style. I dind't found a rtf StringBuilder or somesthing similar to use the Text property, but the binding of Document is also not possible.
Did I miss something?
If you take a look at the documentation for RichTextBox, you will see that by default it uses the RtfFormatter. You can use a RichTextBoxFormatBar attached to the RichTextBox in order to style your plain text.
Ok, a little more in detail: I am reading dynamicly different files and want to display them as one text. I want to show the name of the files on the top of each section ant the text below. To sort this a little bit, I want to make this headers (filenames) bold. The best way for me seems to be a rtf, but I didn't have a rtf. So I created a document, but this wasn't bindable.
How would you bold the headers?
I'm not going to give a specific answer, but there are plenty of solutions online for what you are looking for.
Take a look at the RTF Spec, specifically at the control words for font character formatting properties. You should be able to easily parse the headers, append the appropriate RTF control words to the beginning and end of the string you want to bold.
If you don't want to look up the control spec, perhaps you can use the sample application provided in the repository with the RichTextBox, make a string bold, and see how it returns the RTF formatted string.
Here's a sample:
Text: RichTextBox
RTF Output:
{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs18\f2\cf0 \cf0\ql{\f2 {\b\ltrch RichTextBox}\li0\ri0\sa0\sb0\fi0\ql\par} } }
Would it not be helpful to enable binding on Document? I did it in this way and it seems to work.