First, we define the table structure.
Our Small and Large tables have a fairly simple structure. For
example, the small table structure is defined in a XAML design file
- SmallTable.xaml.
<Table Name="ItemsTable" CellSpacing="10"
BorderBrush="Black" BorderThickness="2" TextAlignment="Justify">
<Table.Columns>
<TableColumn Width="120"/>
<TableColumn Width="180"/>
<TableColumn Width="120"/>
<TableColumn Width="140"/>
<TableColumn Width="140"/>
</Table.Columns>
<TableRowGroup Background="White" DataContext="{Binding
Source={StaticResource InputData}, Path=[0]}">
<TableRow>
<TableCell>
<Paragraph>
<TextBlock
TextWrapping="Wrap" Text="{Binding Path=Columns[0]}"/>
</Paragraph>
</TableCell>
<TableCell>
<Paragraph>
<TextBlock
TextWrapping="Wrap" Text="{Binding Path=Columns[1]}"/>
</Paragraph>
</TableCell>
<TableCell>
<Paragraph>
<TextBlock
TextWrapping="Wrap" Text="{Binding Path=Columns[2]}"/>
</Paragraph>
</TableCell>
<TableCell>
<Paragraph>
<TextBlock
TextWrapping="Wrap" Text="{Binding Path=Columns[3]}"/>
</Paragraph>
</TableCell>
<TableCell>
<Paragraph>
<TextBlock
TextWrapping="Wrap" Text="{Binding Path=Columns[4]}"/>
</Paragraph>
</TableCell>
</TableRow>
</TableRowGroup>
</Table>;
Refer to the MSDN
WPF Table Overview for more information on how to define WPF
tables. Note that we are using Table and not Grid because we need
to place our table in a Flow Document. Although Grid can be wrapped
in a UI container so as to appear in a flow document, it cannot be
split over multiple pages.
Our table definition contains a single row with five columns. We
will see later on how to duplicate this row so that there is one
for every item in the data source so as to achieve list binding
in code. Our data source is defined as follows:
<c:TextDataProvider x:Key="InputData" FileName="text6.txt"/>
Our TextDataProvider is a custom-written class that extracts text
from a tab separated input file. It supplies this text to the targets
via the binding indicated by the DataContext and Binding attributes:
<TableRowGroup Background="White" DataContext="{Binding
Source={StaticResource InputData}, Path=[0]}">
... indicates that this row group is bound to the first line of
the file.
<TextBlock TextWrapping="Wrap" Text="{Binding
Path=Columns[0]}"/>
... indicates that the text block in this cell is bound to the
first column of the line.
The large table structure is almost identical to the small table
structure. It is defined in LargeTable.xaml. Because the pagination
is done automatically by the flow document paginator, the implementation
of the two tables is identical apart from the small differences
in the XAML table definitions. The difference between the table
definitions is that they bind to different input files and have
different numbers of columns.
|