Ugrás a tartalomhoz

.NET Programming Technologies

Gergely Kovásznai, Csaba Biró

Eszterházy Károly College

2. fejezet - Introduction (written by Csaba Biró)

2. fejezet - Introduction (written by Csaba Biró)

Windows Presentation Foundation (WPF) is regarded as the successor of Windows Forms in desktop application development. Although WPF can be considered different than traditional Windows Forms, it is based on a number of principles which form the basis of existing desktop frameworks. The largest and the most important difference is that the code responsible for the appearance of application distinct from the code describes the functionality of the application. It is only one of the several technological innovation.

Breaking the WinForm traditions, WPF based on graphics technology now is DirectX instead of GDI/GDI+. DirectX is due to direct access to any type of user interface can be created. Complex three-dimensional graphics can be planned, but you can use the rich graphical effects for business applications (anti-aliasing, transparency, animation). Due to the hardware acceleration, the DirectX relieves the processor as possible during the graphics rendering burdens the video card (GPU) instead. They become much faster the intensive graphics tasks such as playing animations.

In the traditional Windows Forms applications the cancellation/revolution tied the developers who usually designed it for a standard definition monitor (e.g: 1024 x 768). One of the biggest problem in the case of traditional Windows applications, that the user interface was not scalable. The previous problem can be eliminated due to the WPF, because the graphic elements are not rasterized, but vector-based. Consequently, each items can be arbitrarily resized. Another great advantage is that the vector-based images occupy less space than the raster elements. However, it shouldbe noted that the WPF will continue to support raster graphics.

Device-independent units

The WPF generated for the dimension-treatment of the window and all the elements called device independent units (device-independent unit – DIU), which is one-ninety-sixth part of an inch. In the case of a standard Windows DPI setting (96 dpi) corresponds exactly to a phisically real pixel.

2.1. egyenlet -

Physical   Unit   Size   =   DUI   Size × System   DPI

2.2. egyenlet -

1 96 inch ⋅ 96   dpi   =   1   pixel

A 19-inch LCD display for a maximum resolution of 1600 x 1200, the real pixel density can be calculated as follows:

2.3. egyenlet -

Display   DPI = 1600 2   +   1200 2   pixel 19   inch

It follows that the actual size of this display, a 96-pixel wide object is less than 1 inch. While a lower resolution (85 dpi) in the case of 15-inch LCD display, the preceding object is slightly larger than 1 inch.

The WPF introduced the following method of calculation to overcome this problem. Let’s consider an already said to be ordinary resolution (120 dpi). In this case, 120 pixels are necessary to fill 1 inch. In WPF, the logical units can be transformed into pixels with the following calculation model:

2.4. egyenlet -

= 100   dpi

2.5. egyenlet -

Physical   Unit =   DUI   Size × System   DPI

2.6. egyenlet -

= 1 96 ⋅ 120   dpi = 1 . 25   pixel

So a 120 dpi resolution corresponds to a DIU 1.25 pixel. Thus, the previously examined 96 DIU wide button, the physical size: 120 pixels (96x 1.25=120).

Of course, other units may be used, such as „in” (inch), „pt” (pixels), „cm” (centimetre). The default unit is „px” (pixel)

II.1 Example Units


    <Button Width="200" Height="30">

        <Label Content="Hello World!" FontSize="12"/>


    <Button Width="200pt" Height="30pt">

         <Label Content="Hello World!" FontSize="12pt"/>