0

I'm making a text editor with WPF. I'm using a FlowDocument element wrapped in a RichTextBox. My goal is to add extra information to each new paragraph that is created at runtime (see example). As in, each time the user creates a new paragraph, this extra information is displayed.

<RichTextBox x:Name="richText">

        <FlowDocument IsOptimalParagraphEnabled="True"
                      IsHyphenationEnabled="True"
                      Name="flowDoc">     

            <!--set it's "paragraph template" here and 
                just bind all of the FlowDocument text to a 
                property in my ViewModel-->             
           
        </FlowDocument>
<RichTextBox>

The first "extra information" would be the number of the paragraph. The same way code editors specify the line number, I want the user to be able to see the paragraph number.

The second "extra information" would be a set of stats about the paragraph. Be it, world count, estimated reading time, etc etc etc.

--

At first, my plan was to create a flowdocument, set it's paragraph template to a grid with a textblock for the paragraph number, another one for the stats, and so on. But from what I've gather, this is not possible.

(Coming from ListViews, ListBoxes etc, I'm used to be able to set a template to the children of this controls. Almost as using an ForEach loop.)

I'm looking for a way to accomplish what's in the linked picture, the best idea I have is to, somehow, access the paragraphs positions and some other control generate the "extra information".

  • Is this possible? If so, any suggestion?
  • Is there a better way?

Thank you. Any idea would be greatly appreciated.

Jay
  • 1
  • 1
  • 1
    Welcome to StackOverflow. If you only want paragraphs in your document you could turn it around and have a ListView with your metainformation and flowdocuments rendering each paragraphs. Otherwise you might be able to wrap each paragraph in a BlockUIContainer as propsed in this [answer](https://stackoverflow.com/a/3636883/2248894). But to do so you would still have to add a FlowDocument in each block container to render the paragraph and since you can't use templates you would have to manually manage the content. – ChronosMOT Nov 15 '20 at 19:52
  • Thank you, I'm gonna check that out. I'll post an answer if I succeed :) – Jay Nov 15 '20 at 22:49

0 Answers0