I had a similar problem: I need a text area that could contain my text, knows how to wrap it, fills in its parent control and scrolls.
At first I tried using TextBlock with ScrollViewer, and I think it worked, but for some reason I wanted to use FlowDocument instead of FlowDocumentScrollViewer. This last one did not work, and I just could not leave the battle unattended, so I tried to find solutions, and here's how I got here. I tried to apply workarounds presented in the answers to the original question, however, none of them I have developed (I use .NET 4.5, it may work in other versions, but I do not know about it).
I also tried to use one FlowDocument, but the control contains some user interface elements that I do not need. So, I came up with a different solution.
<ScrollViewer VerticalScrollBarVisibility="Auto"> <FlowDocumentScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"> <FlowDocument>
It is right. It works! Calling ScrollViewer.ScrollToBottom () just works! ScrollViewer allows you to scroll, and FlowDocumentScrollViewer removes user interface elements from FlowDocument. Hope this helps!
Apparently, my design had a flaw, because this way the FlowDocument does not scroll using the mouse scroll wheel. However, setting the IsHitTestVisible property of the FlowDocumentScrollViewer control to False allows this.
Kohányi Róbert
source share