title: WPF TextBlock Height
body: <p>I'm adding TextBlocks dynamically but I have problems with the heights. </p>
  
  <p>Sometimes the text appear cut. In addition, seems that the application assigns the same height for all elements.</p>
  
  <p>The xaml:</p>
  
  <pre><code>&lt;ScrollViewer Grid.Column="2" x:Name="DetailInfoScroll"  
                Margin="25,0,50,0"
                Style="{StaticResource HorizontalScrollViewerStyle}"&gt;
      &lt;VariableSizedWrapGrid Grid.Column="2" Margin="25,0,50,35" 
                             HorizontalAlignment="Left"  
                             VerticalAlignment="Center" 
                             x:Name="StkText"&gt;                      
      &lt;/VariableSizedWrapGrid&gt;
  &lt;/ScrollViewer&gt;
  </code></pre>
  
  <p>and the code:</p>
  
  <pre><code>var txt = new TextBlock
  {
      Text = text,
      TextWrapping = TextWrapping.Wrap,
      TextAlignment = TextAlignment.Justify,
      FontSize = 14,
      Margin = new Thickness(0, 0, 25, 15),
      MaxWidth = 400,
      LineStackingStrategy = LineStackingStrategy.MaxHeight,
      VerticalAlignment = VerticalAlignment.Center,
      HorizontalAlignment = HorizontalAlignment.Left
  };
  
  txt.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
  var desiredSizeNew = txt.DesiredSize;
  txt.Height = desiredSizeNew.Height;
  
  StkText.Children.Add(txt);
  </code></pre>
  
  <p>Demo:
  <img src="https://i.stack.imgur.com/Gpfow.png" alt="Demo"></p>