1 回答

TA貢獻1886條經(jīng)驗 獲得超2個贊
您可以直接在元素上設置屬性Block:
var brushConverter = new BrushConverter();
var tableBorderBrush = brushConverter.ConvertFrom("#CCCCCC");
tableBorderBrush.Freeze();
var headerCellBorderBrush = brushConverter.ConvertFrom("#FFFFFF");
headerCellBorderBrush.Freeze();
private void drawLogTable()
{
Table oTable = new Table() { BorderThickness = new Thickness(1), BorderBrush = tableBorderBrush }
// Add the header row with content,
currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Date time"))) { BorderThickness = new Thickness(0, 1, 0, 0), BorderBrush = headerCellBorderBrush });
currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Directory"))) { BorderThickness = new Thickness(0, 1, 0, 0), BorderBrush = headerCellBorderBrush });
currentRow.Cells.Add(new TableCell(new Paragraph(new Run("File"))) { BorderThickness = new Thickness(0, 1, 0, 0), BorderBrush = headerCellBorderBrush });
// Read file and add rows
...
foreach (string line in existingFoldersArray)
{
...
// Add new row
oTable.RowGroups[0].Rows.Add(new TableRow());
currentRow = oTable.RowGroups[0].Rows[countLines];
...
//Add the row's cells with their borders set
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(dateTime))) { BorderThickness = new Thickness(0, 0, 0, 1), BorderBrush = tableBorderBrush });
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(directory))) { BorderThickness = new Thickness(0, 0, 0, 1), BorderBrush = tableBorderBrush });
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(file))) { BorderThickness = new Thickness(0, 0, 0, 1), BorderBrush = tableBorderBrush });
...
}
...
}
行的邊框是單元格的邊框。要設置行的邊框,TableCell必須設置每行的邊框。
我強烈建議使用 XAML 來DataTemplates完成此任務。這更容易、更易讀、更容易理解并且更靈活。您還可以使用 XAML 設計器的所見即所得功能。
- 1 回答
- 0 關(guān)注
- 272 瀏覽
添加回答
舉報