WPF的应用,可以帮助我们简单的实现MAC一样的图形界面效果。而且其应用范围也是比较广泛的。在这里就为大家介绍一下WPF文档打印的相关实现方法。#t#
WPF文档打印XAML代码:
- < Button Width="200"
Click="InvokePrint">
Invoke PrintDialog< /Button>
WPF文档打印C#代码:
- string printFileName =
@"C:\TestForPrint.xps";
- public void InvokePrint
(object sender, Routed
EventArgs e)
- {
- // 打印对话框,设置属性
- PrintDialog pDialog =
new PrintDialog();
- pDialog.PageRangeSelection =
PageRangeSelection.AllPages;
- pDialog.UserPageRangeEnabled
= true;
- // 这里你还可以设置对话框的MaxPage,
MinPage, PageRange, Printable
AreaHeight, PrintableAreaWidth,
PrintQueue, PrintTicket属性值等。
- // 显示对话框,如果用户点击“打印”
按钮,则返回true。
- Nullable< Boolean> print =
pDialog.ShowDialog();
- if (print == true)
- {
- XpsDocument xpsDocument =
new XpsDocument(printFileName,
FileAccess.ReadWrite);
- FixedDocumentSequence fixedDocSeq =
xpsDocument.GetFixedDocumentSequence();
- pDialog.PrintDocument(fixedDocSeq.Do
cumentPaginator, "Test print");
- }
- }
以上这段代码示例就是WPF文档打印的实现方法。