I am developing a WPF application that will be displayed in a Full-HD LCD screen (42 inch).
In addition, I need to accommodate the controls in absolute positions.
In the development environment I can not see a window in length 1920×1080 (this is the fixed resolution of the targeted screen).
What is the best practice to accomplish this task?
WPF uses Device Independent Units for specifying width/heights/positions/thicknesses, etc.
1 DIU/DIP = 1 physical pixel when your screen DPI is set to 96dpi…..but 1 DIU = a different number of physical pixels when the DPI is not 96dpi.
If you use a
Canvasthen it positions elements using DIUs.Now you imply that you want to position absolutely in terms of pixel coordinates.
So to do this with the
Canvasno matter what the current DPI setting is, you have to use a scaling trick (you can do this with aViewBox, or aLayoutTransform).The example below shows one way to achieve it (my screen is 1366×768….you can change it to Full HD).
It looks at the DPI of the system and gets the
Canvasscaled down whenever the DPI goes up. This allows you to use Canvas coordinates that really mean pixel coords.If you are able to change the users screen to 96dpi then there is no need to do the scaling trick because 1 DIU = 1 physical pixel at 96dpi…no rescaling needed.
At the 96 DPI setting (Smaller – 100%) the screen looks like this:
At the 120 DPI setting (Medium – 125%) (i.e. 96 x 1.25 = 120DPI) the screen looks like this when using my ScaleBackToPixels technique above (i.e. it looks the same as the first screen).
At the 120 DPI setting (Medium – 125%) (i.e. 96 x 1.25 = 120DPI) the screen looks like this when you don’t do any adjustments at all (notice how the circle is bigger, and the font and size of the Button).
All 3 images side by side for comparison: