title: Transform Screen.PrimaryScreen.WorkingArea to WPF dimensions at higher DPI settings
body: <p>I have the following function in my WPF application that I use to resize a window to the primary screen's working area (the whole screen minus the taskbar):</p>
  
  <pre><code>private void Window_Loaded(object sender, RoutedEventArgs e)
  {
      int theHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
      int theWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
  
      this.MaxHeight = theHeight;
      this.MinHeight = theHeight;
      this.MaxWidth = theWidth;
      this.MinWidth = theWidth;
  
      this.Height = theHeight;
      this.Width = theWidth;
  
      this.Top = 0;
      this.Left = 0;
  }
  </code></pre>
  
  <p>This works very well, as long as the machine's DPI is set at 100%.  However, if they have the DPI set higher, then this doesn't work, and the window spills off the screen.  I realize that this is because WPF pixels aren't the same as "real" screen pixels, and because I'm using a WinForms property to get the screen dimensions.  </p>
  
  <p>I don't know of an WPF equivalent to Screen.PrimaryScreen.WorkingArea.  Is there something I can use for this that would work regardless of DPI setting?</p>
  
  <p>If not, then I guess I need to some sort of scaling, but I'm not sure how to determine how much to scale by.</p>
  
  <p>How can I modify my function to account for different DPI settings?</p>
  
  <p>By the way, in case you're wondering why I need to use this function instead of just maximizing the window, it's because it's a borderless window (WindowStyle="None"), and if you maximize this type of window, it covers the taskbar.</p>