MM们
您可以直接在元素上设置属性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 设计器的所见即所得功能。