我在我的WPF應用程序中綁定了一組要執行的任務(待辦事項列表)的ListView。我希望用戶能夠打印他們的列表並根據MSDN指南創建了以下代碼。 (這是我第一次涉足印刷)爲什麼這個flowdocument表總是打印2列
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值,但沒有成功。
printDialog.PrintDocument(((IDocumentPaginatorSource)StatusBoardViewModel
.GetPrintDocument())
.DocumentPaginator
,"Flow Document Print Job");
我不能告訴你我是如何經常希望我可以隱藏網站我搜索結果。 – 2010-12-24 18:55:28