This is the code I use to get system DPI:
// Get system DPI
Matrix m = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice;
if (m.M11 > 0 && m.M22 > 0)
{
dpiXFactor = m.M11;
dpiYFactor = m.M22;
}
else
{
// Sometimes this can return a matrix with 0s. Fall back to assuming normal DPI in this case.
dpiXFactor = 1;
dpiYFactor = 1;
}
This will be the factor of normal DPI (96) the system has. The system will have a horizontal DPI of dpiXFactor * 96 and a vertical DPI of dpiYFactor * 96. You can test this on Windows 7 by going start menu -> "dpi" and selecting "Make text and other items larger or smaller". 100% means a factor of 1 and a DPI of 96. 125% means a factor of 1.25 and a DPI of 120. 150% means a factor of 1.5 and a DPI of 144.
The fallback logic is due to a customer crash report which I think could have only been caused by the transform matrix having all zeroes. There might be a more reliable way of getting system DPI (pinvoke, maybe?) but I don't know of it.