如何在 WPF 中以编程方式删除 FlowDocument 中表格之间的空白/空白?
我创建了一个新窗口,其中有一个带有 RichTextBox 的 Grid。在每个 RichTextBox 行中,我将显示数学问题的逐步解决方案。
我有一个方法可以返回一个有 1 行和 10 列的表,我将这个表添加到 FlowDocument(最后这个 FlowDocument 到 RichTextBox.Document)〜四次。所有数据都显示无误,但最终效果不佳。换句话说,我在一个循环中添加了 4 个表(1 x 10 个单元格)。
每个表中的数据均基于上一个表。 这是我的代码:
public Table AddRow(List<string> a)
{
Table tableTemp = new Table();
tableTemp.CellSpacing = 0;
int numberOfTable01Columns = 10;
for (int i = 0; i < numberOfTable01Columns; i++)
{
tableTemp.Columns.Add(new TableColumn());
}
tableTemp.RowGroups.Add(new TableRowGroup()); //row Group
tableTemp.RowGroups[0].Rows.Add(new TableRow()); //row 1
TableRow currentRow = tableTemp.RowGroups[0].Rows[0];
currentRow.FontSize = 15;
currentRow.FontWeight = System.Windows.FontWeights.Bold;
foreach (var list in a)
{
currentRow.Cells.Add(new TableCell(new Paragraph(new Run(list))));
}
for (int i = 0; i < currentRow.Cells.Count; i++)
{
currentRow.Cells[i].BorderBrush = brushes.Black;
currentRow.Cells[i].BorderThickness = new Thickness(1);
currentRow.Cells[i].Padding = new Thickness(0);
}
tableTemp.Margin = new Thickness(0);
tableTemp.Padding = new Thickness(0);
return tableTemp;
}
,
public void XAMLWindowResult()
{
resultWindow = new ResultWindow();
grid = new Grid();
grid.Name = "grid1";
ColumnDefinition cd1 = new ColumnDefinition();
RowDefinition rd1 = new RowDefinition();
grid.ColumnDefinitions.Add(cd1);
grid.RowDefinitions.Add(rd1);
flowDocument1 = new FlowDocument();
foreach(var p in ProblemDataParagraph())
{
flowDocument1.Blocks.Add(p);
}
flowDocument1.PagePadding = new Thickness(0);
richTextBox = new RichTextBox();
richTextBox.Document.Blocks.Clear();
richTextBox.FontSize = 30;
Grid.SetRow(richTextBox,0);
Grid.SetColumn(richTextBox,0);
}
,
public void ShowFinally()
{
richTextBox.Document = flowDocument1;
grid.Children.Add(richTextBox);
resultWindow.Content = grid;
resultWindow.Show();
}
,
public void AddNextTable(Table a)
{
flowDocument1.Blocks.Add(a);
flowDocument1.Blocks.LastBlock.Padding = new Thickness(0);
flowDocument1.Blocks.LastBlock.Margin = new Thickness(0,
while (counter < 6)
{
StaticVariables.counterOcurrence = 0;
for (int i = 0; i < 4; i++) //cykl 1 ok cykl 2 not
{
Operation1(i);
Operation2(i);
textResult.AddNextTable(tableResult.AddRow(tableDataList.Table1Row2(i)));
Operation3(i);
}
counter++;
textResult.Cicle();
}
textResult.ShowFinally();
当我向 FlowDocument 添加段落时,我可以简单地通过 Paragraph.Margin
和 Paragraph.Padding
对其进行调整。
但在表中没有人工作(table.Margin = new Thickness(0)
; table.Padding = new hickness(0)
; flowDocument1.Blocks.LastBlock.Margin = new Thickness(0,0)
; table.CellSpacing = 0
; Negative Margin)。可能我遗漏了一些明显的想法,但有可能做到吗?
我在 c# 中没有找到关于这个的主题,只有在 xaml 中。
提前致谢!