title: Grid inside a StackPanel: why do auto and * behave strangely?
body: <p>My google and stackoverflow search-fu have failed me, so I present to the community this question.</p>
  
  <p>(This is all generated using VS2010 and .NET 4.0, in a blank default WPF Solution)</p>
  
  <p>Consider the following XAML:</p>
  
  <pre><code>&lt;StackPanel Orientation="Horizontal"&gt;
      &lt;Grid&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="20"/&gt;
              &lt;ColumnDefinition Width="*"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
  
          &lt;Border Name="aborder" Grid.Column="0" Grid.ColumnSpan="2" 
                      Background="Red" Width="200"/&gt;
          &lt;Border Name="aborder2" Background="Green"/&gt;
  
      &lt;/Grid&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>What would you predict the width of "aborder2" to be? </p>
  
  <p>If you guessed "20 pixels", you would be wrong. The correct answer is 110 pixels.</p>
  
  <p>Consider this XAML:</p>
  
  <pre><code>    &lt;StackPanel Orientation="Horizontal"&gt;
      &lt;Grid&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="20"/&gt;
              &lt;ColumnDefinition Width="Auto"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
  
          &lt;Border Name="aborder" Grid.Column="0" Grid.ColumnSpan="2" 
                      Background="Red" Width="200"/&gt;
          &lt;Border Name="aborder2" Background="Green"/&gt;
  
      &lt;/Grid&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>What would you predict the width of "aborder2" to be?</p>
  
  <p>If you guessed either 20 pixels or 110 pixels, you would be wrong. The correct answer is 200 pixels.</p>
  
  <p>I cannot figure this out and it's driving me insane. It seems like the answer should be obvious; clearly there's some interaction between an auto-filling grid column and the stackpanel that causes the grid to freak out. But it just doesn't seem to make <em>sense</em> - whatever rules are governing this behavior seem to be arbitrary. Why 110 pixels? Why not 109 pixels or 100 pixels? I would understand if the auto-sized column failed to expand fully or something, but to have the fixed-width column randomly ignore its width has left me a burnt out shell of a developer.</p>
  
  <p>Any help or guiding lights would be much appreciated!</p>