title: Different values for screen size and wpf-window size
body: <p>i stumbled across a curiosity in WPF which i couldn't explain myself an which i couldn't solve by searching online. So i hope one of you is able to give me a hint to understand my mistake.</p>
  
  <p>Problem: The wpf-window dimensions seems to be 16 units bigger than the screen-resolution. The 16 pixels/units are independent from dimension (windowwidth, windowheight) and screen resolution. 
  The Problem is shown in the following Application:</p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Height="250" Width="350"&gt;
      &lt;DockPanel Margin="10,10,0,0"&gt;
          &lt;DockPanel Width="152" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Left"&gt;
              &lt;TextBlock x:Name="displayHeight" HorizontalAlignment="Left" Margin="0,5,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="60"/&gt;
              &lt;Label Content="Displayheight" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30"/&gt;
  
          &lt;/DockPanel&gt;
  
          &lt;DockPanel Width="148" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Left"&gt;
              &lt;TextBlock x:Name="displayWidth" HorizontalAlignment="Left" Margin="0,5,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="60"/&gt;
              &lt;Label Content="Displaywidth" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30"/&gt;
  
          &lt;/DockPanel&gt;
          &lt;DockPanel Width="162" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Left"&gt;
              &lt;TextBlock HorizontalAlignment="Left" Margin="0,5,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Text="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Width="60"/&gt;
              &lt;Label Content="Windowheight" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="92"/&gt;
  
          &lt;/DockPanel&gt;
          &lt;DockPanel Width="153" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Left"&gt;
              &lt;TextBlock HorizontalAlignment="Left" Margin="0,5,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Text="{Binding ActualWidth, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Width="60"/&gt;
              &lt;Label Content="Windowwidth" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30"/&gt;
  
          &lt;/DockPanel&gt;
  
      &lt;/DockPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Diagnostics;
  using System.Windows;
  using System.Windows.Forms;
  using System.Drawing;
  
  namespace WpfApplication1
  {
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
  
              IntPtr ownerHandle = Process.GetCurrentProcess().MainWindowHandle;
              WpfScreen currentScreen = WpfScreen.GetScreenFrom(ownerHandle);
              Rect workingArea = currentScreen.WorkingArea;
  
              this.displayHeight.Text = workingArea.Height.ToString();
              this.displayWidth.Text = workingArea.Width.ToString();
          }
      }
  
      public class WpfScreen
      {
          public static WpfScreen GetScreenFrom(IntPtr windowIntPTR)
          {
              Screen screen = System.Windows.Forms.Screen.FromHandle(windowIntPTR);
              WpfScreen wpfScreen = new WpfScreen(screen);
              return wpfScreen;
          }
  
          private readonly Screen screen;
  
          internal WpfScreen(System.Windows.Forms.Screen screen)
          {
              this.screen = screen;
          }
  
          public Rect WorkingArea
          {
              get { return this.GetRect(this.screen.WorkingArea); }
          }
  
          private Rect GetRect(Rectangle value)
          {
              return new Rect
              {
                  X = value.X,
                  Y = value.Y,
                  Width = value.Width,
                  Height = value.Height
              };
          }
      }
  }
  </code></pre>
  
  <p>Basically the code is needed to set the max-Values for Height/Width of an Excel-Addin to the available working area of the display. The above application is just a very simple example to illustrate the problem.</p>
  
  <p>For me it would be ok to just know that the 16 pixels are universally valid and independent from hard-/software. Nevertheless it would be great to get an Explanation whats the reason for this behaviour.</p>
  
  <p>Greetings and THX in advance,</p>
  
  <p>Sven</p>