如何在WPF中实现与Silverlight相同的打印功能?



我们正在将SilverLight应用程序迁移到WPF中,在我们的打印应用程序中,我们使用了System.Windows.Printing。相同的命名空间在 WPF 中不可用,它具有 System.Drawing.Printing 命名空间,因为此现有功能无法按预期工作。我们需要为此编写新的打印。有什么方法可以在不编写新代码的情况下实现相同的目标。

在 WPF 中使用所选打印机打印文件的实现

private static void PrintFile(string pathToFile)
{
PrintDialog pDialog = new PrintDialog();
bool? print = pDialog.ShowDialog();
if (print == true)
{
string printerName = pDialog.PrintQueue.FullName;
Process p = new Process
{
StartInfo = new ProcessStartInfo()
{
Arguments = """ + printerName + """,
CreateNoWindow = true,
Verb = "PrintTo",
FileName = pathToFile
}
};
p.Start();
}
}

最新更新