Each container has its own layout
logic??”some stack elements, others arrange them in a grid of invisible cells, and so on. If
you??™ve programmed with Windows Forms, you??™ll be surprised to find that coordinate-based
layout is strongly discouraged in WPF. Instead, the emphasis is on creating more flexible layouts
that can adapt to changing content, different languages, and a variety of window sizes.
For most developers moving to WPF, the new layout system is a great surprise??”and the first
real challenge.
In this chapter, you??™ll see how the WPF layout model works, and you??™ll begin using the basic
layout containers. You??™ll also consider several common layout examples??”everything from a
basic dialog box to a resizable split window??”in order to learn the fundamentals of WPF layout.
Understanding Layout in WPF
The WPF layout model represents a dramatic shift in the way Windows developers approach
user interfaces. In order to understand the new WPF layout model, it helps to take a look at
what??™s come before.
In .NET 1.x, Windows Forms provided a fairly primitive layout system. Controls were fixed
in place using hard-coded coordinates. The only saving grace was anchoring and docking??”
two features that allowed controls to move or resize themselves along with their container.
Anchoring and docking were great for creating simple resizable windows??”for example, keeping
OK and Cancel buttons stuck to the bottom-right corner of a window, or allowing a
TreeView to expand to fill an entire form??”but they couldn??™t handle serious layout challenges.
Pages:
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196