15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

layout ❘ 1001<br />

Figure 35-15 shows the output of the Canvas panel with the positioned children Label, TextBox, <strong>and</strong> Button.<br />

figure 35-15 figure 35-16<br />

dockPanel<br />

grid<br />

The DockPanel is very similar to the Windows Forms docking functionality. Here, you can specify the area<br />

where child controls should be arranged. DockPanel defines the attached property Dock, which you can set<br />

in the children of the controls to the values Left, Right, Top, <strong>and</strong> Bottom. Figure 35-16 shows the outcome<br />

of text blocks with borders that are arranged in the dock panel. For easier differentiation, different colors<br />

are specified for the various areas:<br />

<br />

<br />

<br />

Menu<br />

<br />

<br />

Toolbar<br />

<br />

<br />

Status<br />

<br />

<br />

Left Side<br />

<br />

<br />

Remaining Part<br />

<br />

<br />

<br />

code snippet LayoutDemo/DockPanelWindow.xaml<br />

Using the Grid, you can arrange your controls with rows <strong>and</strong> columns. For every column, you can specify a<br />

ColumnDefinition. For every row, you can specify a RowDefinition. The sample code lists two columns<br />

<strong>and</strong> three rows. With each column <strong>and</strong> row, you can specify the width or height. ColumnDefinition has a<br />

Width dependency property; RowDefinition has a Height dependency property. You can define the height<br />

<strong>and</strong> width in pixels, centimeters, inches, or points, or by setting it to Auto to determine the size depending<br />

on the content. The grid also allows star sizing, whereby the space for the rows <strong>and</strong> columns is calculated<br />

according to the available space <strong>and</strong> relative to other rows <strong>and</strong> columns. When providing the available space<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!