title: Stopping WPF TextBox from growing with text
body: <p>I am trying to modify my simple control so that the text box does not grow as the user types in long text.  I took a look at some solutions posted here at Stackoverflow that suggest using a Grid and an invisible Border and binding the Width of the text box to the ActualWidth of the Border, but I can't seem to get it to work in my setup.</p>
  
  <p>Here is the xaml of my control:</p>
  
  <pre><code>&lt;StackPanel Margin="5,0"&gt;
  &lt;WrapPanel Margin="0,0,0,5"&gt;
    &lt;TextBlock Foreground="White" Margin="0,0,2,0"&gt;TEXT&lt;/TextBlock&gt;
    &lt;TextBlock Foreground="#FF0099CC" FontWeight="Bold"&gt;MORE TEXT&lt;/TextBlock&gt;
  &lt;/WrapPanel&gt;
  &lt;Border Margin="2,4,0,4" BorderThickness="1" SnapsToDevicePixels="True" Background="Black"
          BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"&gt;
    &lt;StackPanel Orientation="Horizontal"&gt;
      &lt;Image Source="..\Resources\zoom.png" Width="13"/&gt;
      &lt;TextBox Foreground="White" Background="Black" BorderBrush="Transparent"&gt;THIS IS SOME TEXT&lt;/TextBox&gt;
    &lt;/StackPanel&gt;
  &lt;/Border&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>Any ideas?  I need the zoom.png to appear "inside" of the text box so I use a horizontal stack panel and just place the image and text box side by side, both surrounded by the same border.</p>
  
  <p>Is there a way for me to stop my text box from auto growing as text is typed?</p>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Below is the xaml I am testing with.</p>
  
  <pre><code>&lt;Window x:Class="Desktop.Shell"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:composite="http://www.codeplex.com/CompositeWPF"
      Title="MyShell" Height="50" Width="900"
      WindowStyle="None"
      ShowInTaskbar="False"        
      AllowsTransparency="True"
      Background="Transparent"
      ResizeMode="CanResizeWithGrip"
      WindowStartupLocation="CenterScreen"&gt;
    &lt;Border BorderBrush="Black"
                  BorderThickness="1.5"
                  CornerRadius="5"
                  Background="Gray"&gt;
      &lt;ItemsControl composite:RegionManager.RegionName="MainRegion"&gt;
        &lt;ItemsControl.ItemsPanel&gt;
          &lt;ItemsPanelTemplate&gt;
            &lt;WrapPanel&gt;&lt;/WrapPanel&gt;
          &lt;/ItemsPanelTemplate&gt;
        &lt;/ItemsControl.ItemsPanel&gt;
      &lt;/ItemsControl&gt;
    &lt;/Border&gt;
  &lt;/Window&gt;
  
  
  &lt;UserControl x:Class="Desktop.SearchTextBox"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Height="50" Margin="0"&gt;
    &lt;StackPanel Margin="5,0"&gt;
      &lt;WrapPanel Margin="0,0,0,5"&gt;
        &lt;TextBlock Foreground="White" Margin="0,0,2,0"&gt;TEXT&lt;/TextBlock&gt;
        &lt;TextBlock Foreground="#FF0099CC" FontWeight="Bold"&gt;MORE TEXT&lt;/TextBlock&gt;
      &lt;/WrapPanel&gt;
      &lt;Border Margin="2,4,0,4" BorderThickness="1" SnapsToDevicePixels="True" Background="Black"
          BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"&gt;
          &lt;Grid x:Name="grdTest"&gt;
            &lt;Image HorizontalAlignment="Left" Source="..\Resources\zoom.png" Width="13"/&gt;
            &lt;TextBox Margin="16,0,0,0"  Foreground="White" Background="Black" BorderBrush="Transparent" Width="{Binding ElementName=grdTest, Path=ActualWidth}"&gt;THIS IS SOME TEXT&lt;/TextBox&gt;
          &lt;/Grid&gt;
      &lt;/Border&gt;
    &lt;/StackPanel&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>I just add my user control to the Window's MainRegion.</p>