title: Anyone know the algorithm used to size Grid columns with spanning cells? (WPF)
body: <p>Using the WPF Grid control is easy when your child elements are always contained within a single grid cell (i.e. there is no column/row spanning). A fixed width column stays the requested fixed width, an auto column will indeed size itself to be as wide as the widest cell in the column. Star columns share any remainder space according to their relative star values. All is simple in the world.</p>
  
  <p>But once you have a cell that spans two or more columns the width of the columns becomes more complicated to calculate and indeed seems counter-intuitive. Here is a trivial example of what I mean. We can define two columns with the first as auto and the second as fixed at 30 pixels.</p>
  
  <pre><code>&lt;Grid.ColumnDefinitions&gt;
      &lt;ColumnDefinition Width="Auto"/&gt;
      &lt;ColumnDefinition Width="30"/&gt;
  &lt;/Grid.ColumnDefinitions&gt;
  </code></pre>
  
  <p>Now we define a button that spans both of the columns and happens to measure at 80 pixels wide. (On my machine with my font and theme settings etc...)</p>
  
  <pre><code>&lt;Button Grid.ColumnSpan="2" Content="QWERTYUIOP"/&gt;
  </code></pre>
  
  <p>We need to allocate the 80 pixels width of the button across the two spanning columns. Given the second column is fixed at 30 I would expect 30 to be allocated against that column and the remaining 50 go to the first column. Because the first column is auto it seems the obvious thing to do.</p>
  
  <p>But no. If you try this in practice you will find that the first column is 0 pixels and the second column has become the full 80. Even though that second column is defined as fixed and so should not be growing bigger, it as stretched to the full width of the button. Maybe I am missing something here but that does not seem very logical to me.</p>
  
  <p>So to my actual question. Is there a full description of the logic used by the Grid control for doing this calculations so that I can fully understand how it works? I have searched MSDN and Google and find nothing that describes how spanning elements affect the column widths.</p>