我编写了一个小应用程序,可以通过编程方式创建可视化效果,并尝试在页面上横向打印它(在纵向模式下会被剪辑)。当我打印时,它确实以横向方式显示,但是我的可视化效果仍然被剪辑,好像受到纵向模式的限制。
这是我的代码:
StackPanel page = new StackPanel();
// ... generate stuff to the page to create the visual
PrintDialog dialog = new PrintDialog(); // System.Windows.Controls.PrintDialog
bool? result = dialog.ShowDialog();
if(result.HasValue && result.Value)
{
dialog.PrintTicket.PageOrientation = PageOrientation.Landscape;
Size pageSize = new Size { Width = dialog.PrintableAreaWidth,
Height = dialog.PrintableAreaHeight };
// pageSize comes out to {1056, 816}, which is the orientation I expect
page.Measure(pageSize);
// after this, page.DesiredSize is e.g. {944, 657}, wider than portrait (816).
page.UpdateLayout();
dialog.PrintVisual(page, "Job description");
}
执行后,打印的内容排列正确,但似乎仍被剪裁为816宽度,截断了大量内容。我通过在打印的纸上覆盖另一张纸来检查,发现完全契合。
我是否有误操作测量和排列控件?如何让我的打印机使用横向方向的全部空间?