Intercepting PrintDialog to XPS Document Writer

痞子三分冷 提交于 2021-01-28 03:03:20

问题


Currently I am providing the user with two controls: Save and Print. When the user selects Save, a region of the WPF display is packaged up and sent through a XpsDocumentWriter and the user is prompted and encouraged to sign the new xps document. When the user selects Print, a PrintDialog.PrintVisual prints that same region to a user selected printer.

All well and good, except that Microsoft XPS Document Writer is one of the choices for printers. Is there a way to prevent or intercept the user selection of XPS document writer and send them to the Save method so I can prompt the user to sign the xps document?


回答1:


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.



来源:https://stackoverflow.com/questions/5043761/intercepting-printdialog-to-xps-document-writer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!