FlowDocument强制分页(BreakPageBefore)

9

我是使用C#来创建一个包含表格数据的FlowDocument。

举例:

FlowDocument flowDoc = new FlowDocument();
Table table1 = new Table();
flowDoc.Blocks.Add(table1); 

table1.RowGroups.Add(new TableRowGroup());
table1.RowGroups[0].Rows.Add(new TableRow());
TableRow currentRow = table1.RowGroups[0].Rows[0];
table1.RowGroups[0].Rows.Add(new TableRow());

currentRow = table1.RowGroups[0].Rows[0];
currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Report"))));

我希望能够在每个“数据部分”之后强制进行分页。我找到了BreakPageBefore,但无法弄清如何强制分页。

如果有任何示例将非常棒!

谢谢。

1个回答

18

如果我理解的没错,你想要这样做:

Section section = new Section();
section.BreakPageBefore = true;
section.Blocks.Add(table1);
flowDoc.Blocks.Add(section);

如果你想在表格中断行,我建议最好新建一个表格。


我不确定这是否是我想要的。我想要一种简单的分页符。表格数据... 表格数据... <分页符> 表格数据...等等...如果这就是我想要的,那么我可能错过了它,你能解释一下吗?非常感谢。 - Dan Bater
听起来您想按照 Martin 的建议为每个部分开始一个新表格,例如 <FlowDocument><Table PageBreakBefore="true"><TableData><TableData>...</Table><Table PageBreakBefore="true"><TableData><TableData>.... - Ray Burns
我认为像Ray所描述的那样,在XAML中是最好的方式。每个块类型都有一个PageBreakBefore属性,您可以使用它来告诉FlowDocument应该断开。我认为没有其他方法。到目前为止,我还没有找到类似于PageBreak类型的东西,可以明确地进行分页。 - martin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接