title: Sizing Content to Fill `Client Area` of Window
body: <p>I am having trouble sizing a WPF control (I'll use the <code>Grid</code> control in this example) to the size of the <code>Client</code> area of a <code>Window</code>. I realize that the <code>Grid</code> automatically fills all available space by default, however I require the <code>Grid</code>'s <code>Width</code> to be set manually so that I may bind to it from another control (a DataGrid with one of its column's <code>Width</code>'s set to <code>Star</code> if it makes any difference).</p>
  
  <p>Please consider the following XAML:</p>
  
  <pre><code>&lt;Window x:Class="TestApplication.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Height="768" Width="1024"
          x:Name="mainWindow"&gt;
  
      &lt;ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Auto"&gt;
          &lt;Grid x:Name="testGrid" Background="DarkGray"&gt;
          &lt;/Grid&gt;
      &lt;/ScrollViewer&gt;
  
  &lt;/Window&gt;
  </code></pre>
  
  <p>And the following Code-Behind:</p>
  
  <pre><code>using System.Windows;
  
  namespace TestApplication
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
  
              testGrid.Width = mainWindow.Width - (SystemParameters.BorderWidth * 2);
          }
      }
  }
  </code></pre>
  
  <p>When running this simple application, the <code>Grid</code> has a width that is slightly larger than the <code>Client</code> area of the <code>Window</code>, resulting in a <code>Horizontal Scroll Bar</code> being displayed. If <code>SystemParameters.BorderWidth</code> does not accurately calculate the width of the <code>Window</code>'s border, what does?</p>
  
  <p>As per the most recent MSDN documentation, <code>SystemParameters.BorderWidth</code>: <em>Gets the metric that determines the border width of the nonclient area of a nonminimized window.</em></p>