title: Why is my DataGrid going off screen no matter what solution I try?
body: <p>I am new to C# and WPF trying to get what I should think is a simple thing, but it doesn't work.</p>
  
  <p>I have a data grid being populated by SQL, and no matter what I try, I can't get the <code>Height</code> of the <code>DataGrid</code> to stay within the window. It always just extends down. I want it to be dynamic to the window size.  </p>
  
  <p>My very simple code is below, or at least this most recent iteration.</p>
  
  <pre><code>&lt;Page x:Class="TMSMaintenance.PaymentError"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:TMSMaintenance"
        Title="PaymentError"&gt;
  
      &lt;!--&lt;DataGrid Name="MydataGrid" CanUserAddRows="False" SelectionMode="Single" /&gt;--&gt;
  
          &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="1*"/&gt;              
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;DockPanel Grid.Row="0" VerticalAlignment="Stretch" &gt;
  
              &lt;DataGrid x:Name="MydataGrid" 
                        VerticalAlignment="Stretch" 
                        MinHeight="100" 
                        VerticalScrollBarVisibility="Auto" VerticalContentAlignment="Stretch"&gt;                    
              &lt;/DataGrid&gt;               
          &lt;/DockPanel&gt;           
      &lt;/Grid&gt;        
  &lt;/Page&gt;
  </code></pre>
  
  <p>I have tried wrapping in a <code>ScrollView</code> - it didn't work. I tried setting the <code>Height</code> by binding it to the window - it didn't work.  I have tried the <code>Grid.RowDefinition Height = "*"</code>  and <code>"1*"</code> - it didn't work.  <code>VerticalAlignment = "Stretch"</code> also didn't work.</p>
  
  <p>So what am I missing?</p>
  
  <p>Edit: Maybe I should also say that this is on a <code>Page</code> file called within a frame tag. Not sure if it makes a difference here.</p>
  
  <pre><code> &lt;StackPanel CanVerticallyScroll="True" CanHorizontallyScroll="True"&gt;
          &lt;!-- Navigation --&gt;
          &lt;StackPanel Orientation="Horizontal" Margin="0,10,0,0"&gt;
              &lt;Button Content="Files Lookup" Margin="0,0,10,0"/&gt;
              &lt;Button Content="Payment Error" Margin="0,0,10,0"/&gt;
              &lt;Button Content="Carrier Maintenance" Margin="0,0,10,0"/&gt;
              &lt;Button Content="Payment File" Margin="0,0,10,0" /&gt;
          &lt;/StackPanel&gt;
          &lt;ScrollViewer&gt;
              &lt;Frame x:Name="MainFrame" NavigationUIVisibility="Hidden" &gt;&lt;/Frame&gt;
          &lt;/ScrollViewer&gt;               
      &lt;/StackPanel&gt;
  </code></pre>