Chapter 3. Layout
WPF provides a powerful and flexible array of tools for controlling the layout of the user interface. These tools enable applications to present information to users in a clear and logical way.
There is a fine line between giving developers or designers enough control over the user interface's layout, and leaving them to do all the work. A good layout system should be able to automate common scenarios such as resizing, scaling, and adaptation to localization, but should allow manual intervention where necessary. In this chapter, we will look at how WPF's layout system helps fulfill these goals.
Layout Basics
WPF provides a set of panels—special-purpose user interface elements whose job is to arrange the elements they contain. Each individual panel type offers a straightforward and easily understood layout mechanism. As with all WPF elements, layout objects can be composed in any number of different ways, so although each individual panel type is fairly simple, the flexible way in which they can be combined makes for a very powerful layout system. And you can even create your own layout element types should the built-in ones not meet your needs.
Table 3-1 describes the main panel types built into WPF[14]. Whichever panel you use, the same basic rule always applies: an element's position is always determined by the containing panel. Most panels also manage the size of their children.
Table 3-1. Main panel types
Panel type | Usage |
---|---|
| Lays children out in a vertical ... |
Get Programming WPF, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.