title: WPF: How to make a textbox dynamically sized yet prevent autosizing?
body: <p>I know there are a lot of questions in regard to the auto sizing of text boxes in WPF, but I couldn't find a solution for the following problem.</p>
  
  <p>Consider this simple window:</p>
  
  <pre><code>&lt;Window x:Class="TestVisualBrush.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow" Height="470" Width="608"&gt;
  &lt;ScrollViewer&gt;
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="Auto" /&gt;
              &lt;RowDefinition Height="*" /&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;TextBox&gt;Test&lt;/TextBox&gt;
          &lt;TextBox MinHeight="100" Grid.Row="1" AcceptsReturn="True" &gt;Test&lt;/TextBox&gt;
      &lt;/Grid&gt;
  &lt;/ScrollViewer&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>This implements these two constraints I need:</p>
  
  <ol>
  <li>This setup will make the second text box sized dynamically so that it uses the remaining window space.</li>
  <li>If the window becomes too small for the required minimum size of the <code>ScrollViewer</code>'s contents, the <code>ScrollViewer</code> shows a scrollbar.</li>
  </ol>
  
  <p>However, when you type too much text in the second text box, the <code>ScrollViewer</code> shows a scrollbar, instead of the <code>TextBox</code>. I'd like to stop the text box from increasing its height beyond the space given by the parent <code>Grid</code> originally. I can't use <code>MaxHeight</code> in this case because there is no suitable <code>ActualHeight</code> to bind to (as far as I can see).</p>
  
  <p>Any suggestions on how to solve this (preferably without code-behind)?</p>
  
  <p><img src="https://i.stack.imgur.com/KVCkM.png" alt="Note that the root ScrollViewer should still scroll if its contents are too large for the window."></p>
  
  <p>In HTML what I want would translate to this:</p>
  
  <pre><code>&lt;table height="100%"&gt;
   &lt;tr&gt;
      &lt;td&gt;&lt;input type="text"&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr height="100%"&gt; 
      &lt;td&gt;
            &lt;!-- Uses as much space as it gets, but scrolls if text inside
                 gets too large. Makes outer window scroll if too small
                 for min-height and other controls in table. --&gt;
        &lt;textarea style="height:100%;min-height:100px"&gt;&lt;/textarea&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>