Prev | Current Page 74 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"

But to understand how this
really works, it helps to take a closer look at the WPF measurement system.
WPF Units
A WPF window and all the elements inside it are measured using device-independent units. A
single device-independent unit is defined as 1/96 of an inch. To understand what this means
in practice, you??™ll need to consider an example.
Imagine that you create a small button in WPF that??™s 96 by 96 units in size. If you??™re using
the standard Windows DPI setting (96 dpi), each device-independent unit corresponds to one
real, physical pixel. That??™s because WPF uses this calculation:
[Physical Unit Size] = [Device-Independent Unit Size] 5 [System DPI]
= 1/96 inch 5 96 dpi
= 1 pixel
Essentially, WPF assumes it takes 96 pixels to make an inch because Windows tells it that
through the system DPI setting. However, the reality depends on your display device.
For example, consider a 20-inch LCD monitor with a maximum resolution of 1600 by 1200
pixels. Using a dash of Pythagoras, you can calculate the pixel density for this monitor, as
shown here:
= 100 dpi
In this case, the pixel density works out to 100 dpi, which is slightly higher than what Windows
assumes. As a result, on this monitor a 96-by-96-pixel button will be slightly smaller than
1 inch.
On the other hand, consider a 15-inch LCD monitor with a resolution of 1024 by 768.


Pages:
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86