EDIT:
Ok, it's kind of solved, but it feels dirty:
foreach (ContainerVisual cv in SurfaceNYTR.Helpers.VFTreeHelper.FindVisualChildren<ContainerVisual>(flowDocReader))
{
if (cv.Parent.DependencyObjectType.SystemType.FullName == "MS.Internal.PtsHost.PageVisual")
{
flowDocReader.Width = cv.DescendantBounds.Width;
}
}
I looked in Snoop, and it seems one of the ContainerVisual objects stores the correct width in its DescendantBounds property. Its parent is PageVisual (this class is internal, though, so the string compare with SystemType.FullName or GetType().ToString() was used which probably sucks)
Note: FindVisualChildren finds all children by type, source for it can be found here
My goal is to display the entire contents of a FlowDocument (that is, without paginating) in a column layout. It would have a fixed height, but the width would depend on the contents of the FlowDocument.
My problem is: FlowDocumentReader does not automatically resize to the contents of the FlowDocument. As you see in my XAML below, FlowDocumentReader.Width is 5000 units (just a large number that can accommodate most documents) -- when I make it Auto, it just clips to the width of the ScrollViewer and paginates my stuff!
Is there a proper way of solving this problem?
I also made a screenshot of what this looks like now, but the ScrollViewer scrolls past the end of the document in most cases: https://i.stack.imgur.com/3FSRl.png
<ScrollViewer x:Name="scrollViewer"
HorizontalScrollBarVisibility="Visible"
VerticalScrollBarVisibility="Disabled"
>
<FlowDocumentReader x:Name="flowDocReader"
ClipToBounds="False"
Width="5000"
>
<FlowDocument x:Name="flowDoc"
Foreground="#FF404040"
ColumnRuleWidth="2"
ColumnGap="40"
ColumnRuleBrush="#FF404040"
IsHyphenationEnabled="True"
IsOptimalParagraphEnabled="True"
ColumnWidth="150">
<Paragraph>
Lorem ipsum dolor sit amet, ...etc...
</Paragraph>
<Paragraph>
Lorem ipsum dolor sit amet, ...etc...
</Paragraph>
<Paragraph>
Lorem ipsum dolor sit amet, ...etc...
</Paragraph>
</FlowDocument>
</FlowDocumentReader>
</ScrollViewer>