15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1082 ❘ ChaPTer 37 creAtinG dOcuments with wpf<br />

<strong>and</strong> UpperRoman), or a graphic (Disc, Circle, Square, Box). List can only contain<br />

ListItem elements which in turn can only contain Block elements.<br />

Defining the following list with XAML results in the output shown in Figure 37-7.<br />

<br />

<br />

Monday<br />

<br />

<br />

Tuesday<br />

<br />

<br />

Wednesday<br />

<br />

<br />

figure 37-7<br />

code snippet FlowDocumentsDemo/ListDemo.xaml<br />

Tables<br />

The Table class is very similar to the Grid class that was presented in Chapter 35 to define rows <strong>and</strong> columns.<br />

The following example demonstrates creating a FlowDocument with a Table. To create tables you can add<br />

TableColumn objects to the Columns property. With TableColumn you can specify the width <strong>and</strong> background.<br />

The Table also contains TableRowGroup objects. The TableRowGroup has a Rows property where<br />

TableRow objects can be added. The TableRow class defines a Cells property where TableCell objects can<br />

be added. TableCell objects can contain any Block element. Here a Paragraph is used that contains the<br />

Inline element Run:<br />

var doc = new FlowDocument();<br />

var t1 = new Table();<br />

t1.Columns.Add(new TableColumn<br />

{ Width = new GridLength(50, GridUnitType.Pixel) });<br />

t1.Columns.Add(new TableColumn<br />

{ Width = new GridLength(1, GridUnitType.Auto) });<br />

t1.Columns.Add(new TableColumn<br />

{ Width = new GridLength(1, GridUnitType.Auto) });<br />

var titleRow = new TableRow();<br />

titleRow.Background = new SolidColorBrush(Colors.LightBlue);<br />

var titleCell = new TableCell<br />

{ ColumnSpan = 3, TextAlignment = TextAlignment.Center };<br />

titleCell.Blocks.Add(<br />

new Paragraph(new Run("Formula 1 Championship 2009")<br />

{ FontSize=24, FontWeight = FontWeights.Bold }));<br />

titleRow.Cells.Add(titleCell);<br />

var headerRow = new TableRow<br />

{ Background = new SolidColorBrush(Colors.LightGoldenrodYellow) };<br />

headerRow.Cells.Add(new TableCell(new Paragraph(new Run("Pos"))<br />

{ FontSize = 14, FontWeight=FontWeights.Bold}));<br />

headerRow.Cells.Add(new TableCell(new Paragraph(new Run("Name"))<br />

{ FontSize = 14, FontWeight = FontWeights.Bold }));<br />

headerRow.Cells.Add(new TableCell(new Paragraph(new Run("Points"))<br />

{ FontSize = 14, FontWeight = FontWeights.Bold }));<br />

var row1 = new TableRow();<br />

row1.Cells.Add(new TableCell(new Paragraph(new Run("1."))));<br />

row1.Cells.Add(new TableCell(new Paragraph(<br />

new Run("Jenson Button"))));<br />

row1.Cells.Add(new TableCell(new Paragraph(new Run("95"))));<br />

var row2 = new TableRow { Background =<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!