title: horizontally center vertically maximized WPF window
body: <p>I have a WPF window that has a MaxWidth set, so when I hit the Maximize button, it maximizes vertically but not horizontally.  This is expected behavior.  However, the window always docks to the left side of the screen (Windows 7, if that matters) and I want it to be centered horizontally when Maximized.  I tried adding the following <code>StateChanged</code> event handler, but it doesn't seem to do anything:</p>
  
  <pre><code>private void wdw_mainWindow_StateChanged(object sender, EventArgs e)
  {
      switch (WindowState)
      {
          case WindowState.Maximized:
              var windowWidth = (double)GetValue(WidthProperty);
              Left = (SystemParameters.PrimaryScreenWidth / 2) - (windowWidth / 2);
              break;
      }
  }
  </code></pre>
  
  <p>I set a breakpoint on the <code>switch</code> statement and this code definitely gets hit when I hit the Maximize button in my app.  However, even after <code>Left</code> gets set, the window remains firmly stuck to the left side of the screen.  What's going on?</p>