这是为什么的FlowDocument表始终打印2列 [英] Why is this flowdocument table always printing 2 columns
问题描述
我在我的WPF应用程序一个ListView绑定到的任务集合来执行(A待办事项列表)。我希望用户能够打印他们的名单,并已创建基础上,MSDN准则下面的代码。 (这是我第一次涉足印刷)
I have a ListView in my WPF app that is bound to a collection of tasks to perform (A to-do list). I want the user to be able to print their list and have created the following code based on the MSDN guidelines. (This my first foray into printing)
public FlowDocument GetPrintDocument()
{
FlowDocument flowDoc = new FlowDocument();
Table table = new Table();
int numColumns = 3;
flowDoc.Blocks.Add(table);
for(int x=0;x<numColumns;x++)
{
table.Columns.Add(new TableColumn());
}
GridLengthConverter glc = new GridLengthConverter();
table.Columns[0].Width = (GridLength)glc.ConvertFromString("300");
table.Columns[1].Width = (GridLength)glc.ConvertFromString("50");
table.Columns[2].Width = (GridLength)glc.ConvertFromString("50");
table.RowGroups.Add(new TableRowGroup());
table.RowGroups[0].Rows.Add(new TableRow());
// store current working row for reference
TableRow currentRow = table.RowGroups[0].Rows[0];
currentRow.FontSize = 16;
currentRow.FontWeight = FontWeights.Bold;
currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Subject"))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Due Date"))));
currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Urgency"))));
for (int i = 1; i < issues.Count+1; i++)
{
table.RowGroups[0].Rows.Add(new TableRow());
currentRow = table.RowGroups[0].Rows[i];
currentRow.FontSize = 12;
currentRow.FontWeight = FontWeights.Normal;
currentRow.Cells.Add(new TableCell
(new Paragraph
(new Run
(issues[i - 1].IssSubject))));
currentRow.Cells.Add(new TableCell
(new Paragraph
(new Run
(issues[i - 1].IssDueDate.Date.ToString()))));
currentRow.Cells.Add(new TableCell
(new Paragraph
(new Run
(issues[i - 1].IssUrgency.ToString()))));
}
return flowDoc;
}
当我尝试用下面的代码来打印我一直有我的网页被拆下来中间有2列(每个包含表的3列)。我曾尝试不同的GridLength值,但没有成功。
When I try to print with the following code I always have my page split down the middle with 2 columns (Each containing the 3 columns of the table). I have tried different GridLength values but had no success.
printDialog.PrintDocument(((IDocumentPaginatorSource)StatusBoardViewModel
.GetPrintDocument())
.DocumentPaginator
,"Flow Document Print Job");
感谢
Thanks
推荐答案
我想获得答案的最好办法就是放弃,问,那你自己找吧。
I guess the best way to get an answer is to give up and ask, then you find it yourself.
的问题是在该行打印的页面,而不是flowdoc本身。默认情况下,他们打印2列。更正后的代码是(这也与边距和可打印区域交易):
The issue was in the line to print the pages, not the flowdoc itself. By default they print with 2 columns. The corrected code is (this also deals with the margin and printable area):
PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)
{
FlowDocument flowDoc = statusBoardViewModel.GetPrintDocument();
flowDoc.PageHeight = printDialog.PrintableAreaHeight;
flowDoc.PageWidth = printDialog.PrintableAreaWidth;
flowDoc.PagePadding = new Thickness(25);
flowDoc.ColumnGap = 0;
flowDoc.ColumnWidth = (flowDoc.PageWidth -
flowDoc.ColumnGap -
flowDoc.PagePadding.Left -
flowDoc.PagePadding.Right);
printDialog.PrintDocument(((IDocumentPaginatorSource)flowDoc)
.DocumentPaginator,
"Task Manager Print Job");
}
这是我发现这在马太福音麦克唐纳的临WPF的方式在C#2008,我强烈推荐。
By the way I found this in Matthew MacDonald's "Pro WPF in C# 2008" which I highly recommend.
这篇关于这是为什么的FlowDocument表始终打印2列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!