title: Stop WPF TextBox from growing
body: <p>I have spent two hours researching how to avoid that my WPF TextBox Control grows when a long text has been typed in, but I have not been able to do it, even I have read some answers about it like these ones:</p>
  
  <p><a href="https://stackoverflow.com/questions/3720855/stopping-wpf-textbox-from-growing-with-text">stopping-wpf-textbox-from-growing-with-text</a></p>
  
  <p><a href="https://stackoverflow.com/questions/604952/wpf-allow-textbox-to-be-resized-but-not-to-grow-on-user-input">wpf-allow-textbox-to-be-resized-but-not-to-grow-on-user-input</a></p>
  
  <p><a href="https://stackoverflow.com/questions/4465646/wpf-how-to-stop-textbox-from-autosizing">wpf-how-to-stop-textbox-from-autosizing</a></p>
  
  <p>My code is the following:</p>
  
  <pre><code>&lt;Grid&gt;
        &lt;TextBox Margin="6,6,8,28" Name="textBox1" AcceptsTab="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" AcceptsReturn="True"/&gt;
        &lt;CheckBox Content="Case sensitive" HorizontalAlignment="Left" Margin="7,0,0,2" Name="checkBox1" Height="16" VerticalAlignment="Bottom" /&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>One thing that I tried was:</p>
  
  <pre><code>MaxWidth={Binding ElementName=MyGrid, Path=ActualWidth} 
  </code></pre>
  
  <p>But it did not work for me.</p>
  
  <p>I also tried to add the following property to the Grid:</p>
  
  <pre><code>ScrollViewer.HorizontalScrollBarVisibility="Disabled"
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>&lt;Border x:Name="b" Grid.Column="1"/&gt;
  &lt;TextBox Width="{Binding ActualWidth, ElementName=b}" ....... /&gt;
  </code></pre>
  
  <p>But it did not work either.</p>
  
  <p>I need my control to grow when the user stretches the window, but not to when a long text is inserted.</p>
  
  <p>Do you have a different answer for this problem that I might try?</p>
  
  <p><strong>UPDATE!</strong></p>
  
  <p>I have noticed something very strange: If I stretch manually  the window, the textbox stops growing when a long text is inserted. That's fine. But I need to achieve this without having to stretch the window every time I run the program</p>