title: Why does WindowStartupLocation = CenterScreen place my window somewhere other than the center of the screen?
body: <p><strong>Here's the Window declaration:</strong></p>
  
  <pre><code>&lt;Window
      x:Class="Pse.ExperimentBase.SplashWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Style="{StaticResource _windowStyle}"
      WindowStartupLocation="CenterScreen"
      WindowStyle="None"&gt;
  </code></pre>
  
  <p><strong>Here's the Style declaration:</strong></p>
  
  <pre><code>&lt;Style
      x:Key="_windowStyle"
      TargetType="Window"&gt;
      &lt;Setter
          Property="Width"
          Value="{Binding Path=InitialWindowWidth}" /&gt;
      &lt;Setter
          Property="Height"
          Value="{Binding Path=InitialWindowHeight}" /&gt;
      &lt;Setter
          Property="Icon"
          Value="Resources/MyIcon.ico" /&gt;
      &lt;Setter
          Property="Background"
          Value="{StaticResource _fadedOrangeBrush}" /&gt;
      &lt;Setter
          Property="FontSize"
          Value="11" /&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p><strong>Discussion:</strong></p>
  
  <p>The screen is 1280 X 1024. The window size (determined by the InitialWindowWidth, InitialWindowHeight bindings) is 800 X 600.</p>
  
  <p>When the Window opens, it appears 188, 141 (left, top). This is basically "northwest" of where it should be. If I calculate the true centered values, it should be 240, 212 (left, top).</p>
  
  <p><strong>A clue?</strong></p>
  
  <p>It's always the <em>first</em> window that has the problem. If I open a second instance of the same window, it will show up in the correct location.</p>
  
  <p><strong>Another clue?</strong></p>
  
  <p>The second window instance will <em>only</em> show up in the correct location if I create both instances before opening the first one.</p>
  
  <p>So...</p>
  
  <pre><code>Window win1 = windowFactory.CreateSplashWindow();
  win1.Show();
  Window win2 = windowFactory.CreateSplashWindow();
  win2.Show();
  win1.Hide();
  </code></pre>
  
  <p>...offsets both win1 and win2</p>
  
  <p>But...</p>
  
  <pre><code>Window win1 = windowFactory.CreateSplashWindow();
  Window win2 = windowFactory.CreateSplashWindow();
  win1.Show();
  win2.Show();
  win1.Hide();
  </code></pre>
  
  <p>...offsets win1 but shows win2 dead center.</p>
  
  <p><strong>So my question is:</strong></p>
  
  <p>What is going on here???</p>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Yet another clue. If I add...</p>
  
  <pre><code>Width="800"
  Height="600"
  </code></pre>
  
  <p>...to my Window declaration, the offset problem disappears. This isn't a solution for me, though, because I need the window size to be a preference stored in a settings file. That's why I have the data binding in my Style. (And note, the data binding for the Width and Height works fine--all windows show up as the correct size).</p>
  
  <hr>
  
  <p><strong>EDIT #2:</strong></p>
  
  <p>I did checking of widths and heights while in debug mode and came to this interesting conclusion:</p>
  
  <p>If I create multiple window instances but don't open any windows, the Width and Height properties of all window instances are "NaN".</p>
  
  <p>If I then open just <em>one</em> of the instances, the width and height properties of <em>all</em> window instance are suddenly valid numbers, not just the width and height of the window I opened.</p>
  
  <p>This tells me that WPF defers data-binding until Show() is called on the first window.</p>
  
  <p><strong>--></strong> So now the question becomes: Can I force WPF to do the data-binding <em>before</em> I show the first window?</p>
  
  <hr>
  
  <p><strong>Edit #3:</strong></p>
  
  <p>I just submitted submitted a bug report on this issue to Microsoft. Here is the link:</p>
  
  <p><a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=477598" rel="noreferrer">https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=477598</a></p>
  
  <p><strong>Edit #4: A Workaround</strong></p>
  
  <p>No real resolution on this yet, but I just confirmed that you can work around the problem using a dummy window. Follow these steps:</p>
  
  <ol>
  <li>Create a new XPF Window called "BlankWindow" (see XAML below).</li>
  <li>Create an instance of BlankWindow plus the window you'd like to be centered on the screen (FirstWindow).</li>
  <li>Execute the following code sequence:</li>
  </ol>
  
  <p>...</p>
  
  <pre><code>BlankWindow.Show()
  FirstWindow.Show()
  BlankWindow.Hide()
  </code></pre>
  
  <p>The XAML for my dummy window is nothing more than this:</p>
  
  <pre><code>&lt;Window
      x:Class="Pse.ExperimentBase.Windows.BlankWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="BlankWindow"
      Height="0"
      Width="0"
      WindowStyle="None"&gt;
      &lt;Grid&gt;&lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>I see no noticeable flicker before "FirstWindow" opens, so I consider it a good enough workaround until MS get around to fixing the bug.</p>