Skilled double does not display properly

I'm trying to make some controls the size of which will be set using a qualified double, so that the size of the control will be the same no matter what screen it appears on.

So, I have this converter that converts double to qualified double:

double effectiveValue = cm;
string qualifiedDouble = effectiveValue + "cm";
LengthConverter lc = new LengthConverter();
double converted = (double)lc.ConvertFrom(qualifiedDouble);

The problem is that it is not very effective with respect to system parameters, such as default resolution or default scaling (idk, as it is called in English)

enter image description here

Do you have any information on how you can have the same values ​​in centimeters displayed on any screen for any resolution, any zoom settings, etc.

thank

+4
2

, , EDID, , . EDID :

HKLM\SYSTEM\CurrentControlSet\Enum\\DISPLAY\ + displayId + registryId

, cm

public static double GetCmToPixelRatio()
{
    var diagVector = GetActiveDisplayDiag();

    var width = System.Windows.SystemParameters.PrimaryScreenWidth;
    return width / diagVector.X;
}


public static int GetDPIX()
{
    var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static);

    return (int)dpiXProperty.GetValue(null, null);

}

private static Point GetActiveDisplayDiag()
{
    //get active display
    string wmiQuery = string.Format("Select * from Win32_DesktopMonitor");

    ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery);
    ManagementObjectCollection retObjectCollection = searcher.Get();

    foreach (ManagementObject retObject in retObjectCollection)
    {
        try
        {
            //get display id
            string regPath = (string)retObject.GetPropertyValue("PNPDeviceID");
            if (regPath != null)
            {
                var pathInfo = regPath.Split('\\');
                var displayId = pathInfo[1];
                RegistryKey reg = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\DISPLAY\\" + displayId);
                var firstSubReg = reg.GetSubKeyNames()[0];
                reg = reg.OpenSubKey(firstSubReg + "\\Device Parameters");
                var edid = (byte[])reg.GetValue("EDID");
                return new Point(edid[21], edid[22]);
            }
        }
        catch (Exception) { }
    }
    return new Point();
}

:

public class CmToPixelConverter : IValueConverter
{
    double ratio = DisplayHelper.GetCmToPixelRatio();

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return (double)value * ratio;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
+1

( ) , , , ( , .. - ), ( 100% , ..). , " " .

100% WPF . , 10x10rectangle ( 10cmx10cm) . , . , , .

, 100% , , / "" . DPI . , , . , , . DPI DPI, - , .

, , , , 16: 9/4: 3 .. , , . , . , "", . , , . , .

. " ", . /etc /, , (, winXP vs win7) -.. , , . 100%. , , 100%, , gpu/monitor " ", .

+3

All Articles