The Layout System

The previous XAML example indicates an interesting aspect of XAML interfaces. The XAML didn't set the width of the Border, the StackPanel, the Button, the Image, or the TextBox. Only the UserControl's width was declared. Everything else automatically sized itself, based on the width of its container.

You can create XAML interfaces in which all sizes and positions are explicitly declared, just like you can in older technologies such as Windows Forms. For most applications, that is most assuredly not recommended. You'll take maximum advantage of XAML by using its built-in features for sizing and positioning visual elements. Used properly, these features can allow your application to run at varying resolutions and sizes. (Wouldn't it be nice to stop those arguments about whether to support 800×600 or 1024×768 or 1280×1024?)

Measurement Units

To explicitly set size and position of units in XAML, a special type of unit is used. It can be thought of as a “virtual pixel.” That is, under default conditions (default desktop dots per inch, for example), one unit will correspond to one pixel. But there are some important differences.

First, the properties holding the units are not integers, as would be common with older pixel-based technologies. The properties are of type Double. This allows applications to have a finer grain, which is important if an element is zoomed, for example.

Second, changing factors such as desktop dpi or the browser zoom factor for Silverlight applications ...

Get Professional Visual Basic 2012 and .NET 4.5 Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.