A WPF FlowDocument
can only belong to a single RichTextBox
. However, we'd like to use a single document which can be manipulated at different points (in space and time) in the UI. It will never happen that there are two RichTextBoxes
simultaneously displaying a single document (and can't, because WPF will complain).
Using a MemoryStream
and XamlReader
/Writer
won't work here as we would like to retain a single document and reflect changes wherever it is used, so copying it every time is out.
Is there any other viable way to achieve that? Something you could use as underlying model from which to create FlowDocument
s or so?
Clarification: The RichTextBoxes that use the Document are no longer visible or anywhere in the logical/visual tree when another one will be instantiated. Though I probably can't enforce that they have already been eaten by the GC. Seemingly this causes a problem when re-using the Document immediately after removing the RichTextBox from the window; that still throws an exception that the Document is already used in another control.
Basically be have a set of "wizard pages" that are displayed one after another and it can happen that we re-use the Document on two successive "pages" but instantiate a new RTBox each time. Maybe there's a problem or a better way?