我有一个 WPF 应用程序,我使用外部库生成文档。该库将文档作为 System.Drawing.Printing.PrintDocument 返回。如何在 WPF 中打印此文档?我可以直接使用 Print() 方法,但我需要允许用户选择打印机和设置。如果我使用 WPF PrintDocument 对话框,我不能像在 WinForms dialog.Document 中那样将我的文档设置到它。有没有办法将旧的 PrintDocument 转换为某种 WPF 友好形式?
WinForms 方式:
// get document for printing
PrintDocument document = exporter.GetPrintDocument();
System.Windows.Forms.PrintDialog dialog = new System.Windows.Forms.PrintDialog();
dialog.Document = document;
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
document.Print();
}
WPF方式:
System.Windows.Controls.PrintDialog dialog = new System.Windows.Controls.PrintDialog();
if (dialog.ShowDialog() == true)
{
// how to print old PrintDocument???
dialog.PrintDocument(...);
}
我还尝试在 WPF 中打开 WinForms 对话框,但这是不可能的。只是没有显示对话框。
感谢您的帮助。
最佳答案
我找到了答案。您必须将 UseDialogEx
对话框属性设置为 true
。
关于c# - 在 WPF 中使用 System.Drawing.Printing.PrintDocument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1657737/