title: Give a WPF Grid the width of a ScrollViewer minus the scrollbar
body: <p>I have a WPF UserControl with two Grids above each other. The bottom Grid is in a ScrollViewer. The idea is to have the first Grid be the header of the second Grid. I'm having trouble with the width of the columns however. Both Grids should take up all the space they can (the width of the Window), but the top Grid should of course be a little less wide, because there's a scrollbar on the right of the bottom Grid.</p>
  
  <p>This is the simplified Xaml I've got:</p>
  
  <pre><code>&lt;UserControl&gt;
      &lt;DockPanel&gt;
          &lt;Grid DockPanel.Dock="Top"&gt;
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width="*" /&gt;
                  &lt;ColumnDefinition Width="*" /&gt;
                  &lt;ColumnDefinition Width="*" /&gt;
              &lt;/Grid.ColumnDefinitions&gt;
          &lt;/Grid&gt;
          &lt;ScrollViewer&gt;
              &lt;Grid&gt;
                  &lt;Grid.ColumnDefintions&gt;
                      &lt;ColumnDefinition Width="*" /&gt;
                      &lt;ColumnDefinition Width="*" /&gt;
                      &lt;ColumnDefinition Width="*" /&gt;
                  &lt;/Grid.ColumnDefintions&gt;
              &lt;/Grid&gt;
          &lt;/ScrollViewer&gt;
      &lt;/DockPanel&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>This renders fine actually, except that the most right column of the top Grid extends over the scrollbar, which I want to avoid.!</p>
  
  <p>Here is an image of the result: <a href="http://i.stack.imgur.com/iIt1F.png" rel="nofollow">Grid column and width of scrollbar</a>. The red indicates where the column/cell is now, but I want it to stop at the blue line. I've tried SharedSizeGroups, but that seems to make my Grids small again (not take up the full space of the window).</p>