title: Binding a TextBox's Width to its parent container's ActualWidth
body: <p>I'm loading a <code>Textbox</code> and a <code>Button</code> into a horizontal <code>StackPanel</code> programmatically. The size of the button (which only contains an <code>Image</code>) is fixed, but I can't get the textbox to fill the available width of its parent. This is what the code looks like:</p>
  
  <pre><code>StackPanel parent = new StackPanel() {
    Orientation = Orientation.Horizontal,
    HorizontalAlignment = HorizontalAlignment.Stretch,
    VerticalAlignment = VerticalAlignment.Top,
  };
  
  TextBox textbox = new TextBox() {
    HorizontalAlignment = HorizontalAlignment.Stretch,
    VerticalAlignment = VerticalAlignment.Top,
    //MinWidth = 375,
  };
  
  Button btn = new Button() {
    Content = new Image() {
      MaxHeight = 40,
      MaxWidth = 40,
      MinHeight = 40,
      MinWidth = 40,
      Margin = new Thickness( 0 ),
      Source = new BitmapImage( 
        new Uri( "btnimage.png", UriKind.Relative ) ),
    },
    HorizontalAlignment = HorizontalAlignment.Right,
    BorderBrush = new SolidColorBrush( Colors.Transparent ),
    Margin = new Thickness( 0 ),
  };
  btn.Click += ( ( s, e ) =&gt; OnBtnClicked( s, e, textbox ) );
  
  parent.Children.Add( textbox );
  parent.Children.Add( btn );
  </code></pre>
  
  <p>If I uncomment the <code>MinWidth</code> setting for the textbox it is displayed as I want it to, but I'd like to not have to specify a width explicitly. I tried adding a binding as follows but that doesn't work at all (the textbox just disappears!)</p>
  
  <pre><code>Binding widthBinding = new Binding() {
    Source = parent.ActualWidth,
  };
  passwdBox.SetBinding( TextBox.WidthProperty, widthBinding );
  </code></pre>
  
  <p>Thanks for your help in advance!</p>