3

目前我为用户提供了两个控件:保存和打印。当用户选择保存时,WPF 显示的一个区域被打包并通过 XpsDocumentWriter 发送,并提示并鼓励用户签署新的 xps 文档。当用户选择打印时,PrintDialog.PrintVisual 将同一区域打印到用户选择的打印机。

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

4

1 回答 1

3

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.

于 2011-02-18T18:09:13.387 回答