title: How to determine the width of content or size a container to content
body: <p><strong>EDIT:</strong></p>
  
  <p><em>Ok, it's kind of solved, but it feels dirty:</em></p>
  
  <pre><code>foreach (ContainerVisual cv in SurfaceNYTR.Helpers.VFTreeHelper.FindVisualChildren&lt;ContainerVisual&gt;(flowDocReader))
  {
      if (cv.Parent.DependencyObjectType.SystemType.FullName == "MS.Internal.PtsHost.PageVisual")
      {
        flowDocReader.Width = cv.DescendantBounds.Width;
      }
  }
  </code></pre>
  
  <p><em>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)</em></p>
  
  <p><em>Note: <a href="https://stackoverflow.com/questions/974598/find-all-controls-in-wpf-window-by-type">FindVisualChildren finds all children by type, source for it can be found here</a></em></p>
  
  <hr>
  
  <p>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. </p>
  
  <p>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!</p>
  
  <p>Is there a proper way of solving this problem? </p>
  
  <p>I also made a screenshot of what this looks like now, but the ScrollViewer scrolls past the end of the document in most cases: <a href="https://i.stack.imgur.com/3FSRl.png" rel="nofollow noreferrer">http://i.stack.imgur.com/3FSRl.png</a></p>
  
  <pre><code>&lt;ScrollViewer x:Name="scrollViewer" 
                HorizontalScrollBarVisibility="Visible" 
                VerticalScrollBarVisibility="Disabled"
                &gt;
          &lt;FlowDocumentReader x:Name="flowDocReader" 
                              ClipToBounds="False" 
                              Width="5000"
                              &gt;
              &lt;FlowDocument   x:Name="flowDoc"
                              Foreground="#FF404040" 
                              ColumnRuleWidth="2" 
                              ColumnGap="40" 
                              ColumnRuleBrush="#FF404040" 
                              IsHyphenationEnabled="True" 
                              IsOptimalParagraphEnabled="True" 
                              ColumnWidth="150"&gt;
  
                  &lt;Paragraph&gt;
                      Lorem ipsum dolor sit amet, ...etc...
                  &lt;/Paragraph&gt;
                  &lt;Paragraph&gt;
                      Lorem ipsum dolor sit amet, ...etc...
                  &lt;/Paragraph&gt;
                  &lt;Paragraph&gt;
                      Lorem ipsum dolor sit amet, ...etc...
                  &lt;/Paragraph&gt;
              &lt;/FlowDocument&gt;
          &lt;/FlowDocumentReader&gt;
  &lt;/ScrollViewer&gt;
  </code></pre>