title: WPF Height at Runtime
body: <p>I am new to WPF. A Problem I am trying to solve is how I can get a correct height at runtime.</p>
  
  <p>In my Application I dynamically add Usercontrols to a Stackpanel in the Code behind. The Usercontrol contains a few Texblocks. My Stackpanel is then used as Content for a BookPage and this BookPage is added to a Book(http://wpfbookcontrol.codeplex.com/). The Height of my Stackpanel should not exceed a certain value.</p>
  
  <p>I already figured out that I can use Measure &amp; Arrange to calculate the ActualSize &amp; Height of the Usercontrol:</p>
  
  <pre><code>itemsa.Measure(new System.Windows.Size(double.PositiveInfinity,     double.PositiveInfinity));
  itemsa.Arrange(new Rect(0, 0, 400, itemsa.DesiredSize.Height));
  </code></pre>
  
  <p>At this point the Usercontrol isn't added to the Stackpanel. 400 is the Width my usercontrol shouldn't exceed, but it does, because the Textblock dosn't create automatic linebreaks. When I display the Book the linebreaks are created.</p>
  
  <p>What should I do to solve this Problem?</p>
  
  <p>Thanks in advance.</p>