title: Prevent wrapping TextBlock from affecting layout
body: <p>I've run into this issue a few times and have yet to find a simple solution.  When a <code>TextBlock</code> (with <code>TextWrapping="Wrap"</code>) is embedded inside another element that doesn't specify its width, the <code>TextBlock</code> expands as large as its parent allows instead of first trying to wrap its text.  For example, I'm currently working on a <code>TextBlock</code> <code>ValidationTemplate</code>.  Here's how the template currently handles text longer than the width of the <code>TextBox</code>:</p>
  
  <p><img src="https://i.stack.imgur.com/IAlBF.png" alt="Current validation template"></p>
  
  <p>which is obviously not optimal.  Here's how I'd like it to appear:</p>
  
  <p><img src="https://i.stack.imgur.com/XkqBm.png" alt="Desired validation template"></p>
  
  <p>Here's the XAML for the <code>ControlTemplate</code> that's producing the first layout:</p>
  
  <pre><code>&lt;ControlTemplate&gt;
    &lt;DockPanel LastChildFill="True"&gt;
      &lt;Border DockPanel.Dock="Top" BorderBrush="Red" BorderThickness="1"&gt;
        &lt;DockPanel&gt;
          &lt;AdornedElementPlaceholder x:Name="TargetTextBox" /&gt;
          &lt;Grid x:Name="WarningBoxContainer" Background="Red" Width="{Binding ElementName=TargetTextBox, Path=ActualHeight}" Height="{Binding RelativeSource={RelativeSource Self}, Path=Width}"&gt;
              &lt;Path Margin="5" Stretch="Fill" Fill="#FFFFFFFF" Data="F1 M 26.9166,22.1667L 37.9999,33.25L 49.0832,22.1668L 53.8332,26.9168L 42.7499,38L 53.8332,49.0834L 49.0833,53.8334L 37.9999,42.75L 26.9166,53.8334L 22.1666,49.0833L 33.25,38L 22.1667,26.9167L 26.9166,22.1667 Z "/&gt;
          &lt;/Grid&gt;
        &lt;/DockPanel&gt;
      &lt;/Border&gt;
      &lt;Border DockPanel.Dock="Top" Margin="0,2,0,0"&gt;
        &lt;TextBlock Text="Something very terrible has happened" TextWrapping="Wrap"/&gt;
      &lt;/Border&gt;
    &lt;/DockPanel&gt;
  &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p>Does anyone know how to make a <code>TextBlock</code> wrap before trying to expand?</p>