You??™ll learn more about WPF
data binding in Chapter 16, and data templates in Chapter 17.
Aligning Content
In Chapter 4, you learned how to align different controls in a container using the
HorizontalAlignment and VerticalAlignment properties, which are defined in the base
FrameworkElement class. However, once a control contains content there??™s another level
of organization to think about. You need to decide how the content inside your content control
is aligned with its borders. This is accomplished using the HorizontalContentAlignment
and VerticalContentAlignment properties.
HorizontalContentAlignment and VerticalContentAlignment support the same values as
HorizontalAlignment and VerticalAlignment. That means you can line content up on the
inside of any edge (Top, Bottom, Left, or Right), you can center it (Center), or you can stretch
it to fill the available space (Stretch). These settings are applied directly to the nested content
element, but you can use multiple levels of nesting to create a sophisticated layout. For example,
if you nest a StackPanel in a Label element, the Label.HorizontalContentAlignment
determines where the StackPanel is placed, but the alignment and sizing options of the
StackPanel and its children will determine the rest of the layout.
In Chapter 4, you also learned about the Margin property, which allows you to add whitespace
between adjacent elements.
Pages:
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263