目前我正在为用户提供两个控件:保存和打印。当用户选择保存时,WPF显示器的区域被打包并通过XPSDocumentWriter发送,并提示用户并鼓励签署新的XPS文档。当用户选择打印时,PrintDialog.printDvisual打印到用户所选打印机的相同区域。

一切顺利,除了Microsoft XPS文档编写者是打印机的选择之一。有没有办法阻止或拦截用户选择XPS文档编写器并将它们发送到保存方法,以便我可以提示用户签署XPS文档?

有帮助吗?

解决方案

Disclaimer: I've never used PrintDialog before, but it looks like something like this might work:

System.Windows.Controls.PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)
{
    PrintQueue selectedQueue = printDialog.PrintQueue;
    if (selectedQueue.Name == "Microsoft XPS Document Writer")
    {
        // Run your XPS save & sign code
    }
    else
    {
        // Run your printDialog.PrintVisual() code
    }
}

I don't really like having the printer name hard-coded (I assume it varies with language settings). Possibly there is a better property of PrintQueue that you can use to identify this printer.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top