I am having trouble creating a button with a size of 1 cm on all screens. Seems my app recognizes my screen as a 96 DPI screen while its a 1920 x 1080 17.3 inch screen, that makes it a 127 DPI screen. The problem is that when i try to use the unit "cm" and measure the height of the button with my ruler, it appears smaller that 1 cm. Is there any way to fix that? Can i change my app's DPI to 127? Or am i missing something? with the DPI awareness of WPF? For now if i want to have 1 cm and my DPI is 127, i hard code 50 pixels for height if my DPI was 96 then i would hard code it to 38 pixels, someone also suggested me to change the screen resolution but i cant work with a blurry screen and the resolution changes witch means now i am not working on a 1920 x 1080 screen. What should i do to have 1 cm the same on all screen sizes and on my screen obviously too without having to change the resolution (makes my screen blurry and less resolution)
Asked
Active
Viewed 179 times
0
-
The suggestion was not to change the screen resolution, but the display scaling: https://www.windowscentral.com/how-set-custom-display-scaling-setting-windows-10 – Clemens Dec 14 '20 at 14:52
-
If the display scaling is set correctly, a Button with `Width="1 cm"` will be (more or less exactly) have an actual width of 1 cm. If you can't live with that, you would obviously have to do some calculations from *device independent pixels* to centimeters yourself. For example, multiply all widths by 127/96. The current DPI may then be a configuration parameter of your application. – Clemens Dec 14 '20 at 15:01
-
@Clemens when i change the scaling to 120% my app becomes 1535 x 864, i get the numbers by using this -> {Binding Source={x:Static SystemParameters.PrimaryScreenWidth}} in a textblock text. – Alexei Dec 14 '20 at 15:19
-
Not sure what you are trying to say. PrimaryScreenWidth is of course also a value in DIPs. Seems you have set 125%: 1920/1.25=1536 – Clemens Dec 14 '20 at 16:03
-
While investigating screen scaling, I found that there is an effective screen resolution and a raw screen resolution (among other things). As I recall, the system scales elements based on 96 DPI. When the screen's raw resolution is something else, elements are not scaled as expected. For my 4K monitor, a 1 cm rectangle is about 60% actual size. The raw resolution is 160 DPI - 96/160 = 60%. Check this out and I think you can get what you need: https://github.com/morbius1st/ScreenParameters – Jeff Dec 15 '20 at 03:38
-
I think that this question should be re-opened. The question is not how to use a "real world unit" but how to get WPF to display an object in a "real world" size. If you look at the program I reference, you will see that getting something in a real world size is more complex than just using real world units due to DPI Awareness. – Jeff Dec 15 '20 at 05:03