title: How can I vertically stretch a WPF user control and its components while stretching its parent window
body: <p>I have a user control with a text box and 2 buttons below it.  I want the text box to stretch vertically when the parent window stretches vertically but nothing happens.  Another problem is that the buttons appear bunched up under the text box when the user control is put into a window. But when I view the user control while not in a window the buttons are separated by 1 grid row.  How can I get this to work properly so the text box increases in size when the parent window is stretched vertically and also have the buttons at the bottom stay away from the text box?</p>
  
  <p>Here is the xaml code for the window that uses the user control:</p>
  
  <pre><code>&lt;Window x:Class="SerialNumTool.Views.test2View"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:local="clr-namespace:SerialNumTool.UserControls"
          mc:Ignorable="d"
          Title="test2View" Height="300" Width="300"
          VerticalAlignment="Stretch"&gt;
      &lt;Grid Margin="0,0,0,0"  Background="Cyan" &gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width=".5*"/&gt;
              &lt;ColumnDefinition Width=".5*"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height=".20*"/&gt;
              &lt;RowDefinition Height=".20*"/&gt;
              &lt;RowDefinition Height=".20*"/&gt;
              &lt;RowDefinition Height=".20*"/&gt;
              &lt;RowDefinition Height=".20*"/&gt;
  
          &lt;/Grid.RowDefinitions&gt;
          &lt;StackPanel Name="MainContentAreaStackPanel" Margin="0" VerticalAlignment="Stretch" 
                      HorizontalAlignment="Stretch"
                      Grid.Row="1" Grid.RowSpan="3" Grid.Column="0" Grid.ColumnSpan="2"&gt;
              &lt;local:UserControl2  VerticalAlignment="Stretch" 
                                   HorizontalAlignment="Stretch"&gt;
              &lt;/local:UserControl2&gt;
          &lt;/StackPanel&gt;
  
  
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Here is the user control code:</p>
  
  <pre><code>&lt;UserControl x:Class="SerialNumTool.UserControls.UserControl2"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
               xmlns:local="clr-namespace:SerialNumTool.UserControls"
               mc:Ignorable="d" 
               d:DesignHeight="150" d:DesignWidth="200"
               VerticalAlignment="Stretch"&gt;
      &lt;Grid Margin="0,0,0,0"  Background="Beige" &gt;
          &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width=".5*"/&gt;
                  &lt;ColumnDefinition Width=".5*"/&gt;
              &lt;/Grid.ColumnDefinitions&gt;
              &lt;Grid.RowDefinitions&gt;
                  &lt;RowDefinition Height=".20*"/&gt;
                  &lt;RowDefinition Height=".20*"/&gt;
                  &lt;RowDefinition Height=".20*"/&gt;
                  &lt;RowDefinition Height=".20*"/&gt;
                  &lt;RowDefinition Height=".20*"/&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;StackPanel Background="Green" Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="1" Grid.RowSpan="2"&gt;
          &lt;TextBox x:Name="TextOutputAreaTextBox" 
                        HorizontalAlignment="Stretch" Margin="5"  
                        VerticalAlignment="Stretch" AcceptsReturn="True"
                        VerticalScrollBarVisibility="Auto"
                        TextWrapping="Wrap" /&gt;
  
          &lt;/StackPanel&gt;
          &lt;StackPanel Orientation="Horizontal" Background="Green" Grid.Column="0" Grid.ColumnSpan="2" 
                      Margin="0,0,0,0" Grid.Row="4" Grid.RowSpan="1" HorizontalAlignment="Stretch" &gt;
  
              &lt;Button Content="Operation 2" Margin="5"&gt;&lt;/Button&gt;
              &lt;Button Content="Operation 3" Margin="5"&gt;&lt;/Button&gt;
          &lt;/StackPanel&gt;
  
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>