I'm having a hard time trying to make a RichTextBox's content in my app auto-sized. Specifically, I want the content inside my RichTextBox to be of automatic width (with a MaxWidth boundary), and Wrap when the width exceeds the available space.
The general structure of my UI is as follows:
<RichTextBox (some properties of the RichTextBox here)> <FlowDocument (some properties of the FlowDocument here)> <Paragraph>Paragraph 1</Paragraph> <Paragraph>Paragraph 2</Paragraph> ... <Paragraph>Paragraph n</Paragraph> </FlowDocument> </RichTextBox>
Let me clarify this before moving on: The nature of my content is read-only. However, I'm using a read-write control (RichTextBox), and setting its IsReadOnly property to true, because I need to be able to select content, which is not available for TextBlock.
Text Wrapping is working as expected, but I can't make the RichTextBox's width just small enough so that the content of a paragraph is rendered, and no more than it. It just takes all the available width.
Digging into the documentation on FlowDocument, FrameworkElement and FrameworkContentElement, and also the WPF content model, I've found that the problem might just be that Paragraph extends from FrameworkContentElement, which does not come with all the sizing properties. So even if the FlowDocument tries to make its page as narrow as its content, the content (a collection of blocks) does not expose any "Width" property, thus taking up all the available space.
I've looked at UWP's RichTextBlock, which might be what I'm looking for. However, it's only available in a WPF project via XAML Islands, which requires moving to .NET Core 3.0. Unfortunately I cannot do that because I need the app to run on Windows versions prior to Windows 10.
So at this point I'd like to hear the opinion from someone who knows better about WPF content, on the following questions:
Do controls extending from FrameworkContentElement work like this as designed? (i.e. not having an auto-sizing capability)
Are blocks the only kind of content a FlowDocument can directly contain?
Is there any way supported by the framework to set auto-size for blocks? (Particular case of question N°1)
Can choosing another FlowDocument-visualizer help? e.g. moving to a FlowDocumentScrollViewer.
Is Microsoft still making changes to WPF classes? Or are new features/changes only available in UWP, as a way to encourage developers to move to UWP?
Thank you very much in advance for your time. I'll really appreciate any answers you can provide on this.