How to determine the width of content or size a container to content
Posted
by
ISVK
on Stack Overflow
See other posts from Stack Overflow
or by ISVK
Published on 2011-01-07T16:37:02Z
Indexed on
2011/01/07
19:54 UTC
Read the original article
Hit count: 221
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: http://i.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>
© Stack Overflow or respective owner